2011-11-05 5 views

답변

7

파이썬은 사전을 사전 순으로 정렬하지 않습니다. 실제로 사전을 임의로 주문합니다. 원래 순서를 유지하는 사전 객체가 필요하다면 Python 2.7에서 사용할 수있는 collections.OrderedDict 클래스를 살펴보십시오.

+0

파이썬 2.6과 비슷한 것은 무엇입니까? – Smudge

+3

@samarudge : http://pypi.python.org/pypi/ordereddict –

1
from collections import OrderedDict 

mydict = {'zstuff' : OrderedDict(zzz=True, aaa=True), 
      'astuff' : OrderedDict(zzz=True, aaa=True)} 
관련 문제