split encloser
Chris
aussie2010 at yahoo.com
Wed Apr 16 02:11:51 EDT 2003
Alex Martelli <aleax at aleax.it> wrote in message news:<7Bgma.8749$LB6.237526 at news1.tin.it>...
> Chris wrote:
> ...
> > Thanks Inyeol. Be nice if they gave a small example of using finditer.
>
> How small? E.g., here's how you could rewrite (a simpler version of)
> findall using finditer (warning, untested):
>
> def findall(are, instring):
> return [mo.group(0) for mo in are.finditer(instring)]
>
> Too small? Then perhaps you could mention a larger one...?
>
>
> Alex
I had some small exposure to "iterators" in C++, and I remember them
being used in loops - iterating over the items in a container. The
example you have given appears to create a list from an "iterator"
with no loop. Something called an "iterator" creating a list with no
loop is very perplexing to me. But maybe my problem is I don't
recognize the syntax [ mo.group(0) for ... ]. It looks like a method
call on an object, followed by an incomplete for loop.
More information about the Python-list
mailing list