Sample Input String: "ATATAGTAGATGAATGGGATAGAAAG" Sample Input Pattern: "TAG" Sample Output: 4 7 20
Asked
Active
Viewed 44 times
1 Answers
-2
You can use the re
module for this:
import re
s="ATATAGTAGATGAATGGGATAGAAAG"
print([m.start()+1 for m in re.finditer(re.escape('TAG'), s)])
Will give you a list of the indices. Best to make a function:
def allIndex(w,s):
return [m.start()+1 for m in re.finditer(re.escape(w), s)]

Wasif
- 14,755
- 3
- 14
- 34
-
4This is the accepted answer in the above dupe. As a 10k+ user you should close the question rather then repeat answers... – Tomerikoo Dec 06 '20 at 15:46