For .find()
how would you find the cases in multiple places?
For example:
string = 'banana'
string.find('na')
I want it to return [3, 5]
by creating a blank list and appending it. How would I go about this?
For .find()
how would you find the cases in multiple places?
For example:
string = 'banana'
string.find('na')
I want it to return [3, 5]
by creating a blank list and appending it. How would I go about this?
>>> import re
>>> [m.start()+1 for m in re.finditer('na', 'banana')]
[3, 5]
Based on this answer, you can do:
>>> import re
>>> [m.start() for m in re.finditer('na', 'banana')]
[2, 4]
In most programming languages, you start counts with 0, not 1, that's why the "na"
s start at 2 and 4, not 3 and 5.