0

I don't know how to use "ordereddict" in python 3. I want to sort the keys of dictionary.

11th May 2020, 11:41 PM
Elnaz Sohani
2 Antworten
+ 2
If you want to sort keys in python then use the following syntex you will get the keys as a tupules. dictonary_name.keys() this will return the keys and mainly ordereddict preserves order of keys in which they are added
11th May 2020, 11:59 PM
Ayush Kumar
Ayush Kumar - avatar
+ 2
For many cases, it will be enough to sort the keys the moment you need them, and that is rather easily done with a regular dict. Check this snippet: d = {1: 'a', 3: 'c', 2: 'b'} for key in sorted(d): print(key, d[key])
12th May 2020, 12:06 AM
HonFu
HonFu - avatar