[Tutor] Fwd: findall() returns tuples or string?

Charles Leviton charles.leviton at gmail.com
Thu Mar 7 16:29:12 CET 2013


Thanks Devin.  now I have a better understanding of what happens.
Let me explore finditer- hearing for the first time.


On Mon, Mar 4, 2013 at 8:47 PM, Devin Jeanpierre <jeanpierreda at gmail.com>wrote:

> On Mon, Mar 4, 2013 at 8:22 PM, Charles Leviton
> <charles.leviton at gmail.com> wrote:
> > I have some confusion regarding when findall returns a list of strings
> and
> > when it returns a list of tuples.
> > Would appreciate an explanation.
>
> If there are no groups, it returns a list of strings, where the
> strings are the whole match.
>
> If there is one group, it returns a list of strings, where the strings
> are the content of the group.
>
> Otherwise, it returns a list of tuples of strings, where the tuples
> contain the group contents (the same as if an individual match had its
> groups() method called).
>
> If you want consistency, use finditer instead of findall.
> http://docs.python.org/2/library/re.html#re.finditer
>
> -- Devin
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130307/e7abefea/attachment.html>


More information about the Tutor mailing list