Nested Dictionaries and Lists

We can have nested Dictionaries and Lists, which means "Dictionary within a Dictionary" or "List within a List". This a very interesting and efficient concept. Lets rewind to the example of owning a company and having a 1000 employees. We can have a Dictionary with the Employee names and a Dictionary for each employee with their attributes and other features. This could help us save so much time and computational costs. This is just a small example to show how we can use these different Data Structures in creative and efficient ways. To explain this further, lets just consider an example of having a Car shop, and having Dictionaries to consolidate all the information. Once we are done with this, we will see two examples in the next unit which will be given as an assignment for the Chapter.

carShop = {'Adam': {'car': 'Honda', 'color': 'blue', 'top speed': '200 mph'}, 'Eve': {'car': 'Toyota', 'color': 'red', 'top speed':'250 mph'}}

This is a very basic example of having customer names and the details of the product they bought. It can be used in several ways to display information. Lets move on to a bigger example and then see how we can work around it using Dictionaries.

results matching ""

    No results matching ""