Reverse complement DNA sequences in Python

def rc(self, dna):
complements = str.maketrans({‘a’:’t’, ‘c’:’g’, ‘g’:’c’, ‘t’:’a’, ‘r’:’y’, ‘y’:’r’, ‘m’:’k’, ‘k’:’m’, ‘b’:’v’, ‘d’:’h’, ‘h’:’d’, ‘v’:’b’, ‘A’:’T’, ‘C’:’G’, ‘G’:’C’, ‘T’:’A’, ‘R’:’Y’, ‘Y’:’R’, ‘M’:’K’, ‘K’:’M’, ‘B’:’V’, ‘D’:’H’, ‘H’:’D’, ‘V’:’B’})
rc = dna.translate(complements)[::-1]
return rcThis
This method uses maketrans to make a translation table, which we use to translate the DNA. We then reverse the order of the characters in the sequence

import string

def rc(dna):

complements = string.maketrans('acgtrymkbdhvACGTRYMKBDHV', 'tgcayrkmvhdbTGCAYRKMVHDB')
rcseq = dna.translate(complements)[::-1]
return rcseq