how to get last element of dictionary in python code example
Example 1: python last element in list
bikes = ['trek', 'redline', 'giant']
bikes[-1]
Example 2: get last element of dictionary python
list(dict)[-1]
Example 3: python how to get the last element in a list
some_list = [1, 2, 3]
some_list[-1]
print(some_list)
Example 4: python get the last in dictionary
from collections import OrderedDict
d = OrderedDict()
d['first'] = 1
d['second'] = 2
d['third'] = 3
els = list(d.items())
els[0]
=> ('first', 1)
els[-1]
=> ('third', 3)