Skip to content

Instantly share code, notes, and snippets.

@stephaniemdavis
Created September 8, 2018 16:37
Show Gist options
  • Save stephaniemdavis/cd243a402899ff0d2bb82910e1c12a38 to your computer and use it in GitHub Desktop.
Save stephaniemdavis/cd243a402899ff0d2bb82910e1c12a38 to your computer and use it in GitHub Desktop.
Reusable code for Codewars DNA code challenges
# iterating a string and comparing it to dictionary values
# by adding the result variable, I eliminate redundant and costly printing, which is the PYTHONIC way to develop
d = {'A':'T','T':'A','C':'G','G':'C'}
for k in random_string:
if k not in d:
result = '{} is not valid. {} is the culprit!'.format(random_string,k)
break
else:
result = 'the string is alright.'
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment