-4

Sample Input String: "ATATAGTAGATGAATGGGATAGAAAG" Sample Input Pattern: "TAG" Sample Output: 4 7 20

Prokash Sarker
  • 99
  • 1
  • 1
  • 6

1 Answers1

-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
  • 4
    This 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