[Python-ideas] iter() on steroids

Steven Bethard steven.bethard at gmail.com
Fri Apr 13 19:07:22 CEST 2007


On 4/13/07, Jason Orendorff <jason.orendorff at gmail.com> wrote:
> On 4/13/07, George Sakkis <george.sakkis at gmail.com> wrote:
> > f1,f2 = [iter(open(f)).map(str.rstrip) for f in 'foo.txt','bar.txt']
> > for i,line in (f1[:3] + f2[1:5]).filter(None).enumerate():
> >         print i,line
>
> George, you've got to pick a better example next time.  This one
> is terrifying.  :)

Yeah, that's pretty awful. ;-)  Maybe a more reasonable example::

    # skip the first line
    for line in iter(fileobj)[1:]:
        ....

where currently you'd write::

    # skip the first line
    fileobj.next()
    for line in fileobj:
        ...

I'm floating around -0.5 on this one. The itertools functions I use
most are chain(), izip(), and count(). None of these are particularly
natural as a method of a single iterator object.

STeVe
-- 
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
        --- Bucky Katt, Get Fuzzy



More information about the Python-ideas mailing list