1 / 29

Nested Dictionaries

Nested Dictionaries. CSE 1310 – Introduction to Computers and Programming Christopher Conly University of Texas at Arlington. Nesting Dictionaries. A dictionary with dictionaries as values my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary',

kineta
Download Presentation

Nested Dictionaries

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Nested Dictionaries CSE 1310 – Introduction to Computers and Programming Christopher Conly University of Texas at Arlington

  2. Nesting Dictionaries • A dictionary with dictionaries as values my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} • Outer dictionary brackets?

  3. Nesting Dictionaries • A dictionary with dictionaries as values my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} • Outer dictionary brackets

  4. Nesting Dictionaries • A dictionary with dictionaries as values my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} • Outer dictionary keys?

  5. Nesting Dictionaries • A dictionary with dictionaries as values my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} • Outer dictionary keys

  6. Nesting Dictionaries • A dictionary with dictionaries as values my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} • Outer dictionary values?

  7. Nesting Dictionaries • A dictionary with dictionaries as values my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} • Outer dictionary values

  8. Nesting Dictionaries • A dictionary with dictionaries as values my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} • Inner dictionary brackets?

  9. Nesting Dictionaries • A dictionary with dictionaries as values my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} • Inner dictionary brackets

  10. Nesting Dictionaries • A dictionary with dictionaries as values my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} • Inner dictionary keys?

  11. Nesting Dictionaries • A dictionary with dictionaries as values my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} • Inner dictionary keys

  12. Nesting Dictionaries • A dictionary with dictionaries as values my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} • Inner dictionary values?

  13. Nesting Dictionaries • A dictionary with dictionaries as values my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} • Inner dictionary values

  14. Accessing Nested Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} How do you access 'John'?

  15. Accessing Nested Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} How do you access 'John'? my_dict[123]['name']

  16. Accessing Nested Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} How do you access 'John'? my_dict[123]['name']

  17. Accessing Nested Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} How do you access 'John'? my_dict[123]['name']

  18. Looping and Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} for item in my_dict: ... What is item?

  19. Looping and Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} for item in my_dict: ... What is item? A key. How do we access the name value?

  20. Looping and Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} for item in my_dict: name = my_dict[item]['name'] How do we access the name value?

  21. Looping and Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} for item in my_dict: name = my_dict[item]['name'] How do we access the name value?

  22. Looping and Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} for item in my_dict: name = my_dict[item]['name'] How do we access the name value?

  23. Looping and Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} for item in my_dict: name = my_dict[item]['name'] How do we access the name value?

  24. Looping and Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} for key1 in my_dict: ... What about looping through ‘name’ and ‘age’?

  25. Looping and Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} for key1 in my_dict: for key2 in my_dict[key1]: print my_dict[key1][key2] What about looping through ‘name’ and ‘age’?

  26. Looping and Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} for key1 in my_dict: for key2 in my_dict[key1]: print my_dict[key1][key2] What about looping through ‘name’ and ‘age’?

  27. Looping and Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} for key1 in my_dict: for key2 in my_dict[key1]: print my_dict[key1][key2] What about looping through ‘name’ and ‘age’?

  28. Looping and Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} for key1 in my_dict: for key2 in my_dict[key1]: print my_dict[key1][key2] What about looping through ‘name’ and ‘age’?

  29. Looping and Dictionaries my_dict = {123: {'name': 'John', 'age': 50}, 456: {'name': 'Mary', 'age': 30}} for key1 in my_dict: for key2 in my_dict[key1]: print my_dict[key1][key2] What about looping through ‘name’ and ‘age’?

More Related