Answers for "how to make an ordered dictionary in python"

0

how to make an ordered dictionary in python

# A Python program to demonstrate working of key  
# value change in OrderedDict 
from collections import OrderedDict 
  
print("Before:\n") 
od = OrderedDict() 
od['a'] = 1
od['b'] = 2
od['c'] = 3
od['d'] = 4
for key, value in od.items(): 
    print(key, value) 
  
print("\nAfter:\n") 
od['c'] = 5
for key, value in od.items(): 
    print(key, value) 
""" 
Ouptut:
Before:

('a', 1)
('b', 2)
('c', 3)
('d', 4)

After:

('a', 1)
('b', 2)
('c', 5)
('d', 4)
"""
Posted by: Guest on November-05-2020
0

python Ordered dict to dict

>>> from collections import OrderedDict
>>> dict(OrderedDict([('method', 'constant'), ('data', '1.225')]))
{'data': '1.225', 'method': 'constant'}
Posted by: Guest on July-08-2020

Code answers related to "how to make an ordered dictionary in python"

Python Answers by Framework

Browse Popular Code Answers by Language