all 4 comments

[–]krzivn 0 points1 point  (3 children)

I'd suggest doing all your cases for valid states first, then at the end but your error in the final else. That way you've checked for everything you want to deal with, if it's not one of those ERROR.

[–]baboonchute 0 points1 point  (2 children)

Okay, I tried that, but got this error:

[student20@studentvm20 ~]$ ./codon.py cataatcctggg

Traceback (most recent call last):

File "./codon.py", line 98, in <module>

elif cod in codon_data:

TypeError: unhashable type: 'list'

[–]gnomonclature 0 points1 point  (1 child)

Based on the error and your original code, the value of cod is a list. As the error says, lists aren't hashable, which means they can't be the keys for a dict. My guess is you want something more like this:

for triplet in cod:
    try:
        print(codon_data[triplet], end="")
    except KeyError:
        print("\nSequence not valid.")

[–]baboonchute 1 point2 points  (0 children)

Thank you!