""" Ex 6.7 from "A primer on..." Read structured file data into a nested dictionary, then write the data in a tabular format similar to the file. """ humans = {} with open('human_evolution.txt') as infile: for line in infile: if line[0] == 'H': species = line[:21].strip() when = line[21:37].strip() height = line[37:50].strip() mass = line[50:62].strip() brain = line[62:].strip() info = {'when': when, 'height': height, 'mass': mass, 'brain': brain} humans[species] = info #print(humans) for species, info in humans.items(): w = info['when'] h = info['height'] m = info['mass'] b = info['brain'] #use an f-string and format specifiers to get nice columns line = f'{species:20s} {w:14s} {h:10s} {m:9s} {b}' print(line) """ 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 """