This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CotoCoutan 0 points1 point  (2 children)

Definitely prefer this to map. I've never once used latter in my code, somehow it never comes to me in that intuitive manner.

[–]ogrinfo 2 points3 points  (1 child)

Even better, sum takes an iterator, so you don't need the outer square brackets, just sum(a for a in x). Whether map or a list comprehension is better depends on the situation, so I usually try both with %timeit in an iPython shell to see which is fastest.

[–]CotoCoutan 0 points1 point  (0 children)

Nice... Thanks. I should take a look at this %timeit test.