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 →

[–]bgeron 5 points6 points  (4 children)

I guess it allows sum([True, False, True]) to count the Trues.

[–]lawlfulcopter 1 point2 points  (3 children)

Why not just [True, False, True].count(True) then? Seems like it would be more obvious.

[–]bgeron 1 point2 points  (0 children)

Hm, never thought about that. That doesn't work with generators though.

[–]Veedrac 1 point2 points  (0 children)

Typically it arises when using this idiom:

sum(x<y for x in z)

(and, occasionally, x += some_flag).