I have two sets of lists that are synchronized and look like this:
(by synchronized I mean that ‘A’ in cal belongs to 12 in cpos, and ‘A’ in mal belongs to 11 in mpos)
set1
cpos = [12, 13, 14, 15]
cal = ['A', 'T', 'C', 'G']
set2
mpos = [11, 12, 13, 16]
mal = ['A', 'T', 'T', 'G']
I want to find a match between the two sets, and in this example there is only one match, 13T in cpos&cal and 13T in mpos&mal.
I wrote this script, but it only compares the values by indices it seems, since the match string is empty:
mat = []
for i in xrange(len(cpos)):
if mpos[i] == cpos[i] and mal[i] == cal[i]:
mat.append(cpos[i])
This is what I wanted to get:
mat = [13]
Any ideas how to solve this?
Result:
As per @Janne Karila’s comments below, the following will be more efficient:
Timings: