I have a statement which prints a string relating to a chemical and its desired key values, how do I print the key values corresponding key name?
def chemByString(chemName,chemicals,priority="echo"):
for chemical in chemicals:
chemDict = chemical.toDict(priority)
if chemDict["chemicalName"] == chemName
return chemical
return None
print str(chemByString('O2', allChemicals, priority="echo").chemicalName) + str("{chemicalName:<5s} {charge:<20s}{comment:<20s}".format(**chemByString('O2', allChemicals, priority="echo").toDict()))
Output:
{'tv': 'O2', 'echo': 'O2'} O2 0 O2
Desired Output:
{'tv': 'O2', 'echo': 'O2'} O2 Charge 0 Comment O2
or
Species Charge Comment
{'tv': 'O2', 'echo': 'O2'} O2 0 O2