I am following this:
if else in a list comprehension
but the following small program is generating a syntax error:
def to_rna(dnasequences):
xlate = {'G': 'C', 'C': 'G', 'T': 'A', 'A': 'U'}
return ''.join(xlate[sequence] for sequence in dnasequences if sequence in xlate.keys() else raise ValueError)
The else clause is generating the error.
If I remove the else clause it runs, however, I want to raise a ValueError for any input that is NOT a key in my dictionary 'xlate'.
NOTE I am working on the rna-transcription problem from exercism.io.
I pass 5 unit tests but I fail the three unit tests requiring a ValueError for invalid input.