There are mainly three ways to loop over dictionaries:
- By keys:
for key in truck_wheel.keys(): print(key) # prints (in any order) 'Ix', 'Iy', 'name',...
or equivalently:
for key in truck_wheel: print(key) # prints (in any order) 'Ix', 'Iy', 'name',...
- By value:
for value in truck_wheel.values(): print(value) # prints (in any order) 1.0, 20.0, 17.0, 'wheel', ...
- By item, that is, key/value pairs:
for item in truck_wheel.items(): print(item) # prints (in any order) ('Iy', 1.0), ('Ix, 20.0),...
Please consult Section 14.4: Shelves for a special dictionary object for file access.