Why can’t I sort a list of dicts in 3.x? Why do I get “TypeError: ‘

Python 2’s dictionary sort order was quite involved and poorly understood. It only happened to work because Python 2 tried to make everything orderable.

For your specific case, with {'name': ...} dictionaries with a single key, the ordering was determined by the value for that single key.

In Python 3, where dictionaries are no longer orderable (together with many other types), just use that value as the sorting key:

server_list.sort(key=lambda x: x[0]['name'], reverse=False)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)