1# import the right class
2from collections import OrderedDict
3
4# create and fill the dictionary
5d = OrderedDict()
6d['first'] = 1
7d['second'] = 2
8d['third'] = 3
9
10# retrieve key/value pairs
11els = list(d.items()) # explicitly convert to a list, in case it's Python 3.x
12
13# get first inserted element
14els[0]
15=> ('first', 1)
16
17# get last inserted element
18els[-1]
19=> ('third', 3)