Here is way to get the last key of an OrderedDict in Python3.
I need to get last value of an OrderedDict in Python3 without conversions to list
.
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
>>> from collections import OrderedDict
>>> dd = OrderedDict(a=1, b=2)
>>> next(reversed(dd))
'b'
>>> next(reversed(dd.keys()))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument to reversed() must be a sequence
>>> next(reversed(dd.items()))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument to reversed() must be a sequence
>>> next(reversed(dd.values()))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument to reversed() must be a sequence