-2

For example in 'GATTACA' I want to find all the 'A's.

I would want the positions 1,4,6.

Using the '.find' method only gives me the location of the first 'A' but not the rest.

I was wondering if there was another method that allowed you to find all 'repeat' characters in a string?

Daniel
  • 1
  • 1

1 Answers1

5
In [26]: s = 'GATTACA'

In [27]: [i for i,char in enumerate(s) if char=="A"]
Out[27]: [1, 4, 6]
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241