get last value from dictionary python code example
Example 1: python get last item in a list
my_list = ["I", "Love", "Python"]
last_item_in_list = my_list[-1]
# last_item_in_list = "Python"
Example 2: python get the last in dictionary
# import the right class
from collections import OrderedDict
# create and fill the dictionary
d = OrderedDict()
d['first'] = 1
d['second'] = 2
d['third'] = 3
# retrieve key/value pairs
els = list(d.items()) # explicitly convert to a list, in case it's Python 3.x
# get first inserted element
els[0]
=> ('first', 1)
# get last inserted element
els[-1]
=> ('third', 3)