Let's say I have this dictionary:
mydict = {'1': ['a', 'b', 'c'],
'2': ['d', 'e', 'f'],
'3': ['g', 'h', 'i'],
'4': ['j', 'k', 'l'],
'5': ['m', 'n', 'o']}
According to the Python documentation,
The keys() method of a dictionary object returns a list of all the
keys used in the dictionary, in arbitrary order
When I call mydict.keys()
method, it will give me a list of keys in the mydict
without any particular order like this:
['1', '3', '2', '5', '4']
My Question is does the key list(above) generated by .keys()
method has the same order everytime I call it? I have tried it using for loop like this:
for i in range(100):
print mydict.keys()
It seems to me that the resulting list has always the same order. But I just want to confirm that there is no hidden case that will change the order of output list.
In other word, if i use mydict.keys()[0]
, will I get the same item every time?