[BangPypers] Dictionary : An elementary question

Jeffrey Jose jeffjosejeff at gmail.com
Wed Aug 18 22:18:52 CEST 2010


Excellent responses so far.

Dictionaries are optimized for retrieving key/value pairs. And to achieve
that, it compromises on the order in which stuff is stored.

This and more is very nicely presented in the Pycon 2010 talk - The Mighty
Dictionary. Highly recommended.

http://us.pycon.org/2010/conference/schedule/event/12/

<http://us.pycon.org/2010/conference/schedule/event/12/>/jeff

On Wed, Aug 18, 2010 at 11:04 PM, Vinay Shastry <vinayshastry at gmail.com>wrote:

> 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
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>


More information about the BangPypers mailing list