0

I have dictionary where I want to maintain order of insertion. How can I do that?

    nested_dict = {
        "name" :"Your Name",
        "age" : "Your Age",
        "contact" : {
            "Street" : "Your Street",
            "State" : "Your home state",
            "Phone" : "Your Phone Number"
        }
    }
    print(nested_dict)

This is the output I got from 1st try: {'contact': {'Street': 'Your Street', 'State': 'Your home state', 'Phone': 'Your Phone Number'}, 'name': 'Your Name', 'age': 'Your Age'}

Output from 2nd try: {'name': 'Your Name', 'contact': {'Street': 'Your Street', 'Phone': 'Your Phone Number', 'State': 'Your home state'}, 'age': 'Your Age'}

BlackCoffee
  • 171
  • 3
  • 10
  • 2
    Ordered Dictionaries: https://docs.python.org/2/library/collections.html#collections.OrderedDict – Hoopdady Mar 14 '17 at 20:42
  • After using Ordered Dictionaries,is nested_dict dictionary anymore? Can I access it using key instead of using indices? – BlackCoffee Mar 14 '17 at 22:44

0 Answers0