[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accumulator



alexander wrote:

> > > Yes, I agree that for many cases comprehensions can be clearer, but I also
> > > think for many they aren't, notably when you've got more than one sequence:
> > > 
> > >       map(add, xs, ys)
> > > 
> > > is, to me, better than:
> > > 
> > >     [x + y for (x,y) in zip(xs,ys)]
> > 
> > I think it's just a matter of which you learned first. zip is useful to
> > know for other contexts anyhow.
> 
> Zip is easily the python function I like best (for one thing, because it
> allows elegant uses of infinite sequences), so I would be even willing to
> sacrifice map if it would bring more people closer to the wonders of zip :)

footnote: zip(...) is of course the same thing as map(None, ...)
with a different stop condition in case the lengths differ.

def zip(*args):
    return fancymap(STOP, None, *args)

def map(func, *args):
    return fancymap(PAD_WITH_NONE, func, *args)

</F>