[BangPypers] Dictionary : An elementary question

Vinay Shastry vinayshastry at gmail.com
Wed Aug 18 19:34:32 CEST 2010


On 18 August 2010 22:58, Anand Shankar <anand_shankar at 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


More information about the BangPypers mailing list