Here is a nested loop of used cars
cars = {1: { 'year': 2006, 'make': 'Buick', 'model': 'Regal', 'color': 'blue' },
2: { 'year': 2007, 'make': 'Chevrolet', 'model': 'Cobalt', 'color': 'white'}}
print(cars)
for p_id, p_info in cars.items():
print(‘\nCar ID’, p_id)
for key in p_info:
print(key + ‘:’, p_info[key])
# Nested dictionary is an unordered collection of dictionary
# Slicing Nested Dictionary is not possible.
# We can shrink or grow nested dictionary as need.
# Like Dictionary, it also has key and value.
# Dictionary are accessed using key.’
The output shows the dictionary. The numbers are the key. The for statements break it down the list by key and values.
{1: {'year': 2006, 'make': 'Buick', 'model': 'Regal', 'color': 'blue'}, 2: {'year': 2007, 'make': 'Chevrolet', 'model': 'Cobalt', 'color': 'white'}}
Car ID 1
year: 2006
make: Buick
model: Regal
color: blue
Car ID 2
year: 2007
make: Chevrolet
model: Cobalt
color: white