Personal notes
In [25]: D = dict(a=1,b=2,c=3)
In [26]: D.keys()
Out[26]: ['a', 'c', 'b']
The list is returned normally. So it can be used as an iterator as it is
In [27]: for key in D.keys(): print "key:{}, value:{}".format(key, D[key])
key:a, value:1
key:c, value:3
key:b, value:2
In [3]: D = dict(a=1,b=2,c=3)
In [4]: D
Out[4]: {'b': 2, 'c': 3, 'a': 1}
In [5]: D.keys()
Out[5]: dict_keys(['b', 'c', 'a'])
It's not a list, but an object called dict_keys!
Recommended Posts