This exercise will walk you through the creation of a dictionary.
names.txt file. This file contains common names of some species. Load this into a list.species.txt file. This file contains chemical formulae for some species.names.txt are the values and the data from species.txt are the keys.for loopfor loop should iterate over the representation created by the zip function. You can refer to the example around line 32 in Lecture 4 for guidance.my_new_dict = {} just before executing the for loop.Note: The same dictionary can be created by executing the following one-liner: species_dict_2 = dict(zip(species, names)).
In [27]:
with open('names.txt') as fnames:
names = fnames.read()
names = names.split('\n')
print(names)
names = filter(None, names)
print(list(names))