Python论坛  - 讨论区

标题:[python-chinese] 字典在for...in..中的赋值顺序问

2006年10月30日 星期一 10:58

lveax.m在gmail.com lveax.m在gmail.com
星期一 十月 30 10:58:53 HKT 2006

hey all.

---------
#!/usr/bin/python

ab = {       'Swaroop'   : 'swaroopch在byteofpython.info',
             'Larry'     : 'larry在wall.org',
             'Matsumoto' : 'matz在ruby-lang.org',
             'Guido' = 'guido在python.org'
     }

for name, address in ab.items():
    print 'Contact %s at %s' % (name, address)

-------
output
-------
$ python using_dict.py

Contact Swaroop at swaroopch在byteofpython.info
Contact Matsumoto at matz在ruby-lang.org
Contact Larry at larry在wall.org
Contact Guido at guido在python.org

这个输出为什么不是
Contact Swaroop at swaroopch在byteofpython.info
Contact Larry at larry在wall.org
Contact Matsumoto at matz在ruby-lang.org
Contact Guido at guido在python.org

这里的赋值是按什么排序的?

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年10月30日 星期一 11:04

limodou limodou在gmail.com
星期一 十月 30 11:04:16 HKT 2006

> 这里的赋值是按什么排序的?

字典的key是无序的。如果要排序需要自已做,或者通过keys()来排,或者通过items()来排。

-- 
I like python!
UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年10月30日 星期一 11:05

Zuggie magicccc在gmail.com
星期一 十月 30 11:05:50 HKT 2006

Dictionary have no order.

----- Original Message -----
From: <lveax.m at gmail.com>
To: <python-chinese at lists.python.cn>
Date: 2006年10月30日 上午 10:58
Subject: [python-chinese] 字典在for...in..中的赋值顺序问题

> hey all.
> 
> ---------
> #!/usr/bin/python
> 
> ab = {       'Swaroop'   : 'swaroopch at byteofpython.info',
>             'Larry'     : 'larry at wall.org',
>             'Matsumoto' : 'matz at ruby-lang.org',
>             'Guido' = 'guido at python.org'
>     }
> 
> for name, address in ab.items():
>    print 'Contact %s at %s' % (name, address)
> 
> -------
> output
> -------
> $ python using_dict.py
> 
> Contact Swaroop at swaroopch at byteofpython.info
> Contact Matsumoto at matz at ruby-lang.org
> Contact Larry at larry at wall.org
> Contact Guido at guido at python.org
> 
> 杩欎釜杈撳嚭涓轰粈涔堜笉鏄?BR> > Contact Swaroop at swaroopch at byteofpython.info
> Contact Larry at larry at wall.org
> Contact Matsumoto at matz at ruby-lang.org
> Contact Guido at guido at python.org
> 
> 杩欓噷鐨勮祴鍊兼槸鎸変粈涔堟帓搴忕殑?
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese


Jianhua Zhu
Tel: +86-769-87318190     EXT: 164 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年10月30日 星期一 11:07

Jamsa zhujiemao在126.com
星期一 十月 30 11:07:00 HKT 2006

python-chinese£¬ÄãºÃ

×ÖµäÊÇHashµÄ£¬Ôõô»áÓÐ˳Ðò¡£Èç¹ûÒª±£³Ö˳Ðò¿ÉÒÔÓÃÊý×éºÍ×ÖµäÅäºÏʹÓÃ
Jamsa£¬zhujiemao在126.com
2006-10-30 
----- Original Message ----- 
From: lveax.m 
To: python-chinese 
Sent: 2006-10-30, 10:58:53
Subject: [python-chinese] ×ÖµäÔÚfor...in..Öеĸ³ÖµË³ÐòÎÊÌâ


hey all.

---------
#!/usr/bin/python

ab = { 'Swaroop' : 'swaroopch在byteofpython.info',
             'Larry' : 'larry在wall.org',
             'Matsumoto' : 'matz在ruby-lang.org',
             'Guido' = 'guido在python.org'
     }

for name, address in ab.items():
    print 'Contact %s at %s' % (name, address)

-------
output
-------
$ python using_dict.py

Contact Swaroop at swaroopch在byteofpython.info
Contact Matsumoto at matz在ruby-lang.org
Contact Larry at larry在wall.org
Contact Guido at guido在python.org

Õâ¸öÊä³öΪʲô²»ÊÇ
Contact Swaroop at swaroopch在byteofpython.info
Contact Larry at larry在wall.org
Contact Matsumoto at matz在ruby-lang.org
Contact Guido at guido在python.org

ÕâÀïµÄ¸³ÖµÊÇ°´Ê²Ã´ÅÅÐòµÄ?
_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061030/66ec6d8b/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号