
pythonod = OrderedDict([('apple', 1), ('banana', 2), ('cherry', 3)])
od.move_to_end('apple', last=True | False)
print(od) *# OrderedDict([('banana', 2), ('cherry', 3), ('apple', 1)])*OrderedDict에서 항목을 제거하고 반환 기본적으로 마지막 항목을 제거
`pythonod = OrderedDict([('apple', 1), ('banana', 2), ('cherry', 3)])
last_item = od.popitem(last=True | False)
print(last_item) *# ('cherry', 3)*
print(od) *# OrderedDict([('apple', 1), ('banana', 2)])*`
OrderedDict에 새로운 항목을 추가하거나 기존 항목을 업데이트
pythonod = OrderedDict([('apple', 1), ('banana', 2)])
od.update({'cherry': 3, 'apple': 5})
print(od) *# OrderedDict([('apple', 5), ('banana', 2), ('cherry', 3)])*
OrderedDict는 순서가 중요한 상황에서 매우 유용한 데이터 구조
특히 데이터의 삽입 순서를 유지해야 하는 경우나 순서를 조작해야 하는 경우 유용