Ask your own question, for FREE!
Computer Science 22 Online
OpenStudy (anonymous):

Python programming question. Suppose a chemical compound of only C and H atoms is represented by a dictionary mapping each arbitrarily labeled C atom to a list of atoms it is bound to. For example, acetylene would be {'C1':['C2', 'C2', 'C2', 'H1'], 'C2':['C1', 'C1', 'C1', 'H2']}. Write a function which checks two compounds against each other, and returns true when both compounds are the same structurally. I am a bit lost on this one. I can't think of an easy way, only of a pretty complicated one. It won't fit into the opening post though.

OpenStudy (anonymous):

Alright, the only way I can think of doing this is to check whether for each C atom in compound1 a C atom exists with the exact same chemical environment. That is all direct neighbors are of the same type and have the same amount of single, double or triple bonds, the same is true for all neighbors of the neighbor atoms, and so on.

OpenStudy (anonymous):

i would make list of the keys in the dictionary of one molecule and check that for each key in that one molecule, the values are the same in the dictionary of the other. and vice versa i guess

OpenStudy (anonymous):

That won't work. Suppose we have c1 == {'C1':['C2','C2','H1','H2'], 'C2':['C1', 'C1', 'C3', 'C3'], 'C3':['C2', 'C2', 'H3', 'H4']} c2 == {'C2':['C1','C1','H1','H2'], 'C1':['C2', 'C2', 'C3', 'C3'], 'C3':['C1', 'C1', 'H3', 'H4']} is_same_compound(c1, c2) should return true, but your version would not.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!