Ad

This will only work with TACG. Will accept lower cased values which are converted internally to upper case before replacement occurs and the compliment is returned.

Code
Diff
  • def reverse_compliment(dna):
        # ensure input is in upper case so replace works correctly
        uppercase_dna = dna.upper()
        # chain compliment replacements, convert to upper case & reverse return value
        return (
            uppercase_dna.replace("T", "a")
            .replace("A", "t")
            .replace("C", "g")
            .replace("G", "c")
            .upper()[::-1]
        )
    • def reverse_compliment(dna):
    • pass
    • # ensure input is in upper case so replace works correctly
    • uppercase_dna = dna.upper()
    • # chain compliment replacements, convert to upper case & reverse return value
    • return (
    • uppercase_dna.replace("T", "a")
    • .replace("A", "t")
    • .replace("C", "g")
    • .replace("G", "c")
    • .upper()[::-1]
    • )