def eval_species(start: int, end: int): mol_start = start while not toks[mol_start].isalpha() and mol_start < end: mol_start += 1 if mol_start == end: raise ValueError('Invalid equation') coeff = ''.join(toks[start:mol_start]) mol_toks = toks[mol_start:end] mol = Molecule.complete_formula(''.join(mol_toks)) return Species(mol, coeff=coeff)