I think I’ve discussed ‘for loops’ before, but I’ll give it another short go here for you.  ‘For loops’, like shown below, help you review groups of information in sets.

 

def countSubStringMatchRecursive(target, key, x):
x = find(target, key, x)
if x == -1:
return 0
else:
return countSubStringMatchRecursive(target, key, x+1) +1

target = ["atgacatgcacaagtatgcat", "atgaatgcatggatgtaaatgcag"]
key = ["a", "atg", "atgc", "atgca"]

for t in target:
for k in key:
print  "There were " + str(countSubStringMatchRecursive(t, k, 0)) + " occurances of your key " + k + " in " + t

 


Here I am going through each list.  Let me revise this code quickly, and I’ll show you how it goes thought each combination.  

 

target = ["atgacatgcacaagtatgcat", "atgaatgcatggatgtaaatgcag"]
key = ["a", "atg", "atgc", "atgca"]

for t in target:
for k in key:
print t + " " + k

 


If I run this piece of code I get this back:

 

atgacatgcacaagtatgcat a
atgacatgcacaagtatgcat atg
atgacatgcacaagtatgcat atgc
atgacatgcacaagtatgcat atgca
atgaatgcatggatgtaaatgcag a
atgaatgcatggatgtaaatgcag atg
atgaatgcatggatgtaaatgcag atgc
atgaatgcatggatgtaaatgcag atgca 

 


As you can tell, it prints each piece of the ‘target’ list against the ‘key’ list.  It is quite handy when attempting to compare and create new information based on varying lists.

On Monday awaits this codes final analysis!  Be ready or be quadratic!