python strange behaviour with dictionary

Petr_?imon,您好!

  The dictionary in Python is out-of-order, so it's correct.

======= 2004-04-11 21:10:36 您在来信中写道:=======

Hi,
this is not exactly wx related question, but I hope someone could have a
glance at the problem.
I have a test.py that says:

fr={'a':12,'b':12,'c':10,'d':9,'e':8,'f':7,'g':6}
for key in fr:
   print fr

when I run it I get:

{'a': 12, 'c': 10, 'b': 12, 'e': 8, 'd': 9, 'g':6, 'f': 7}

From 'b':12 down everything is switched! Why? I have python 2.3.3 on Debian
Thanks for answer and sorry for bothering with this here.
Petr

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

= = = = = = = = = = = = = = = = = = = =
      

礼!

    limodou
    chatme@263\.net
      2004\-04\-11

Exactly.
By definition, dictionary data structures do not provide any sort of key
ordering. if you want that, you must create it, ie:

keys=list(fr)
keys.sort()
for key in keys:
    print key

If you want ordering, use a list or tuple, which do preserve order.

Regards,
Stuart.

···

On Mon, 12 Apr 2004 01:22, limodou wrote:

Petr_?imon,您好!

  The dictionary in Python is out-of-order, so it's correct.