- Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathordereddict.py
More file actions
Latest commit
13 lines (12 loc) · 501 Bytes
/
Copy pathordereddict.py
File metadata and controls
13 lines (12 loc) · 501 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
"""
Write a Python program to create an instance of an OrderedDict using a given dictionary.
Sort the dictionary during the creation and print the members of the dictionary in reverse order
"""
fromcollectionsimportOrderedDict
dict= {'Afghanistan': 93, 'Albania': 355, 'Algeria': 213, 'Andorra': 376, 'Angola': 244}
new_dict=OrderedDict(dict.items())
forkeyinnew_dict:
print (key, new_dict[key])
print("\nIn reverse order:")
forkeyinreversed(new_dict):
print (key, new_dict[key])