In simple term, data within the data is generally called a nested data.
A list within a list or a table within a table are examples of nested data.
Imagine a complex and extensive codes. You can understand that at times it is difficult to understand it quickly. Hence, a good practice is to divide in to smaller groups and find their meaning so gradually you can start unwrapping the whole code.
One simple example is the nested dictionary data.
Now we can add a list within this dictionary to make it a nested data
We are adding cathy under kids.
So now this becomes a nested data. List within dictionary.
And now since kids is a list, we can apply all functions that are applicable to list in order to access data within this list.
In this dictionary, there are key-value pairs. dad is a key and value is john. Similarly kids is a key and it has 2 values peter and cathy. So length of this dictionary is 3 as there are 3 key-value pairs.
We can access values within the key kids and it will show below results.
since kids is a list, we can also use index function to select values within the list. If we want to find the boy within the family, then we can write the below code.
This is a simplistic example but when in a complex code, we are not sure about the type of data within the data we can use type function to reveal it.
Now we know that it is a list and so we can apply all functions that can be applied to any list. This way, selecting values from within the nested data becomes easier.

No comments:
Post a Comment