def parse_list(t, p): """Takes a nested list that represents a chemical formula (returned by the function make_list()), makes an analogous list of atoms, and numbers the atoms in order. t: list of str p: Parser object Returns: list of Atoms """ res = [] for elem in t: if type(elem) == str: #res.append(elem + str(i)) #appends string if elem == 'C': res.append(Atom.Carbon(elem + str(p.i))) #appends atom if elem == 'N': res.append(Atom.Nitrogen(elem + str(p.i))) #appends atom if elem == 'O': res.append(Atom.Oxygen(elem + str(p.i))) #appends atom if elem == 'P': res.append(Atom.Phosphorus(elem + str(p.i))) #appends atom if elem == 'S': res.append(Atom.Sulfur(elem + str(p.i))) #appends atom p.incr() if type(elem) == list: res.append(parse_list(elem, p)) return res