""" Exercise 6.7 from "A primer on...". Read data from file and store in a nested dictionary. """ humans = {} with open('human_evolution.txt') as infile: for line in infile: if line[0] == 'H': name = line[:21].strip() when = line[21:36].strip() height = line[36:49].strip() mass = line[49:60].strip() brain = line[60:].strip() details = {'when':when, 'height':height, 'mass':mass, 'brain volume': brain} humans[name] = details #iterate the dictionary and print a nicely formatted table: for spec, human in humans.items(): #items() returns a list of (key, value) tuples print(f"{spec:20} {human['when']:14} {human['height']:12} {human['mass']:12} {human['brain volume']}") """ Terminal> python humans.py H. habilis 2.2 - 1.6 1.0 - 1.5 33 - 55 660 H. erectus 1.4 - 0.2 1.8 60 850 (early) - 1100 (late) H. ergaster 1.9 - 1.4 1.9 700 - 850 H. heidelbergensis 0.6 - 0.35 1.8 60 1100 - 1400 H. neanderthalensis 0.35 - 0.03 1.6 55 - 70 1200 - 1700 H. sapiens sapiens 0.2 - present 1.4 - 1.9 50 - 100 1000 - 1850 H. floresiensis 0.10 - 0.012 1.0 25 400 """