How to write body function using for loop and return def mat

How to write body function using for loop and return? def match_enzymes(strand, names, sequences): \" \" \" (str, list of str, list of str) rightarrow list of (str, list of int) tuples The first parameter is a DNA strand. The last two parameters are parallel lists: the second parameter is a list of restriction enzyme names, and the third is the corresponding list of recognition sequences. (e.g., if the first item in the second parameter is \'BamHI\', then the first item in the second list might be \'GGATCC\', since the restriction enzyme named BamHI has that recognition sequence.) Return a list of tuples where the first item of each tuple is the name of a restriction enzyme and the second item is the list of indices (in the DNA strand) of the restriction sites that the enzyme cuts. >>> match_enzymes (\"GCTGACGCGG\", (\"Hgal\"], [\"GACGC\"]) [(\"HgaI\", [3])] >>> match_enzymes(\"GAGATCGCA\", (\"Sau3A\"), [\"GATC\"] [(\"Sau3A\", [2])] >>> match_enzymes(\"GGCCGAGGCCTCGAGGCC\", [\"HaeIII\"), [\"GGCC\"]) [(\"HaeIII\", [0, 6, 14])] >>> match_enzymes (\"ATTGCGAGCT\", (\"AluI\", \"KpnI\"], (\"AGCT\", \"GGTACC\"]) [(\"[AluI]\", [6])] \" \" \"

Solution

import re


def match_enzymes(strand,names,sequences):
   # list of results
   pos=[]
   for each in zip(names,sequences): #for each combination of name and sequence
       var = [temp.start() for temp in re.finditer(each[1], strand)] #find all indices
       if var: #if indice there then create a tuple and append to the list
           tup = (each[0], var)
           pos.append(tup)
   return pos

 How to write body function using for loop and return? def match_enzymes(strand, names, sequences): \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site