""" Read data into nested dict humans[name], with the following keys for each species: height, weight, brain volume, when Note: Using split() for processing each line does not work because of multiple arbitrary spaces. A better procedure for this particular file is to use string indexing/slicing to extract each data field. """ filename = 'human_evolution.txt' humans = {} with open(filename) as infile: for line in infile: if line[0] == 'H': name = line[:20].strip() when = line[20:35].strip() height = line[35:50].strip() weight = line[50:60].strip() brain = line[60:].strip() humans[name] = {'when':when,'height':height,'weight':weight,'brain volume':brain} #loop through the dictionary to print the result: for name in humans: h = humans[name] #local variable to reduce typing on next line #Use an f-string with fixed-length data fields: line = f"{name:20} {h['when']:15} {h['height']:10} {h['weight']:10} {h['brain volume']:15}" 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 """