Answers for "python reverse order ordered dict"

1

reverse key order dict python

>>> a = {0:'000000',1:'11111',3:'333333',4:'444444'}
>>> a.keys()
[0, 1, 3, 4]
>>> sorted(a.keys())
[0, 1, 3, 4]
>>> reversed(sorted(a.keys()))
<listreverseiterator object at 0x02B0DB70>
>>> list(reversed(sorted(a.keys())))
[4, 3, 1, 0]
Posted by: Guest on September-14-2020
0

python ordereddict reverse

reverse_dict = collections.OrderedDict(sorted(tempdict.items(), reverse=True)) # Set reverse=True
Posted by: Guest on June-24-2021

Python Answers by Framework

Browse Popular Code Answers by Language