Python complaints
skaller
skaller at maxtal.com.au
Thu Dec 16 12:36:29 EST 1999
Aahz Maruch wrote:
>
> In article <38562655.77A3B3DC at udel.edu>,
> >>>> There's nothing you can do with "map" you couldn't do "more Pythonically"
> >>>> with list comprehensions; e.g.
> >>>> sq = map(lambda a: a**2, x)
> >>>> vs
> >>>> sq = [a**2 for a in x]
> >
> >This is the first I've seen of this notation and it is simple and
> >(reasonably) understandable. But the savings is minimal versus normal
> >Python
> >
> >fx = []
> >for a in x:
> > fx.append(a**2)
> >
> >Am I missing something?
>
> The theory is that because the list comprehension is a single statement,
> you save some loop overhead (just as map() does). For a large, tight
> loop, it can make a difference.
There is also the potential for comprehensions to be evaluated
lazily: this save a HUGE amount of space, and a considerable
amount of time.
--
John Skaller, mailto:skaller at maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
voice: 61-2-9660-0850
More information about the Python-list
mailing list