프로그래밍/Python

[Python] collections.OrderedDict

1q 2017. 8. 31. 01:19

사전형으로 작업할 일이 있을때(JSON 작업?), 순서대로 저장된 사전 형태가 필요할 때 아래와 같이 사용.

import collections

dic = collections.OrderedDict()

dic['a'] = '첫 번째 값'

dic['b'] = '두 번째 값'

for key, value in dic.items():

 print(key, value)