0
I don't know how to use "ordereddict" in python 3. I want to sort the keys of dictionary.
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
+ 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])