📌  相关文章
📜  python 获取字典中的最后一个 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:47.061000             🧑  作者: Mango

代码示例1
# 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)