Is re.findall guaranteed to be "in order?"

J

Joshua Kugler

I tried looking through re.py and sre_compile.py, but I can't really see an
answer to my question.

Experimenting has shown me that re.findall() will return a list with the
matches in the order it found them. Am I lucky so far, or does the
_sre.c's logic dictate the items will be added in order found?

http://svn.python.org/view/python/tags/r25c1/Modules/_sre.c?rev=51334&view=auto
(search for "pattern_findall") seems to indicate they will be added in
order, but can someone with a better handle on Python internals (and quite
frankly, C) confirm this?

Thanks!

j
 
M

MRAB

I tried looking through re.py and sre_compile.py, but I can't really see an
answer to my question.

Experimenting has shown me that re.findall() will return a list with the
matches in the order it found them.  Am I lucky so far, or does the
_sre.c's logic dictate the items will be added in order found?

http://svn.python.org/view/python/tags/r25c1/Modules/_sre.c?rev=51334....
(search for "pattern_findall") seems to indicate they will be added in
order, but can someone with a better handle on Python internals (and quite
frankly, C) confirm this?
They will be returned in order.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top