string1="abc"
string2="abdabcdfg"
I want to find if string1 is substring of string2. However, there are wildcard characters like "." can be any letter, y can be "a" or "d", x can be "b" or "c".
as a result, ".yx" will be substring of string2.
How can I code it using only one loop? I want to loop through string2 and make comparisons at each index. i tried dictionary but I wand to use loop my code:
def wildcard(string,substring):
sum=""
table={'A': '.', 'C': '.', 'G': '.', 'T': '.','A': 'x', 'T': 'x', 'C': 'y', 'G': 'y'}
for c in strand:
if (c in table) and table[c] not in sum:
sum+=table[c]
elif c not in table:
sum+=c
if sum==substring:
return True
else:
return False
print wildcard("TTAGTTA","xyT.")#should be true
.+#->[a-z][bc][ad], and then match that regex. I think this is much better, but it does not use a loop.{'A': '.', ..., 'A': 'x'}, thenAmaps only toxor to., not to both. You could use'A': '.x'or'A': ['x','.']instead; see my answer below (although I do the mapping the other way around).