On 18 August 2010 22:58, Anand Shankar <anand_shan...@yahoo.com> wrote: > During a tutorial python session with my colleagues I was presented with a > basic > question > >>>> d = {'apple':2,'banana':5, 'coke': 6} >>>> print d.keys() > ['coke', 'apple', 'banana'] > > > Question is why does it not return > > ['apple','banana','coke'] <snip> > I have no clues. Any inputs?? >
For this reason: "It is best to think of a dictionary as an unordered set of key: value pairs" http://docs.python.org/tutorial/datastructures.html#dictionaries >>> d = {'apple':2,'banana':5, 'coke': 6} >>> d {'coke': 6, 'apple': 2, 'banana': 5} >>> print d.keys() ['coke', 'apple', 'banana'] -- Vinay S Shastry http://thenub.one09.net _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers