Let's say we have a dictionary inside a dictionary:
people = {
0: {'name': 'John', 'age': 27, 'sex': 'Male'},
4: {'name': 'Marie', 'age': 22, 'sex': 'Female'},
7: {'name': 'Agness', 'age': 25, 'sex': 'Female'}
}
What is a faster way to go through that dictionary? I saw on Internet solution:
for p_id, p_info in people.items():
print("\nPerson ID:", p_id)
for key in p_info:
print(key + ':', p_info[key])
However items function creates from scratch(?) a list of tuples.
I feel like going through dictionary that way is faster:
for key in people:
for value in people[key]:
print(value)
Am I wrong? If yes, why?