-2

given a long string, for example: str = 'abbabaab'

and a short substring: sub = 'ab'.

I want to get a list of all the indexes where the substring can be found, without iterating over the string.

the expected result would be: res = [0, 3, 6]

Zusman
  • 546
  • 4
  • 22

1 Answers1

1

Coming from here:

import re

str = 'abbabaab'
sub = 'ab'

res = [x.start() for x in re.finditer(sub, str)]
print(res)                                            # [0, 3, 6]
DirtyBit
  • 16,151
  • 4
  • 28
  • 54