R
R
ratkke2013-04-16 21:42:26
Python
ratkke, 2013-04-16 21:42:26

start method in python

Good day, I'm a beginner in python, so excuse me if the question is completely stupid, but Google could not answer me (or I asked incorrectly).
Today I was browsing stackoverflow and came across this line of code.
[m.start() for m in re.finditer(r"ab",s)][n]
Actually, this line returns the index of the nth occurrence of the substring ab in the string s.
Actually the question is: how does it work?
I wandered through the Python help, I didn’t find anything sensible about this start. The standard dir didn't give me any answers either.
Finditer returns, which is logical, an iterator, judging by the Python help, but this did not explain the situation to me.

Thank you in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
laQie, 2013-04-16
@ratkke

There is documentation on re, in which everything is painted.

S
SadGnome, 2013-04-16
@SadGnome

MatchObject is returned from finditer, it has a start() method - it returns the index of the beginning of the substring, documentation is here:
docs.python.org/2/library/re.html#match-objects

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question