Python 2 and Python 3
i
is the key, so you would just need to use it:
for i in d:
print i, d[i]
Python 3
d.items()
returns the iterator; to get a list, you need to pass the iterator to list()
yourself.
for k, v in d.items():
print(k, v)
Python 2
You can get an iterator that contains both keys and values. d.items()
returns a list of (key, value) tuples, while d.iteritems()
returns an iterator that provides the same:
for k, v in d.iteritems():
print k, v
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…