Python complaints
Aahz Maruch
aahz at netcom.com
Wed Dec 15 00:11:51 EST 1999
In article <38562655.77A3B3DC at udel.edu>,
Charles Boncelet <boncelet at udel.edu> wrote:
>>> Attribution lost:
>>>>
>>>> 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.
--
--- Aahz (@netcom.com)
Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6
TEOTWAWKI -- 18 days and counting!
More information about the Python-list
mailing list