News for hackers. Stuff that matters.
Re:Go Bloviations by daeken on Tuesday September 25, 2012 @04:23AM (#4569245)
With the sum approach the data set never exists in memory, but is generated as needed; not a big deal for a small set, but it can add up.
Re:Go Bloviations by lclarkmichalek on Tuesday September 25, 2012 @05:00AM (#4569349)
And as in python3, filter returns a generator, not a list, the len call will fail altogether.
Re:Go Bloviations by bjourne on Tuesday September 25, 2012 @08:12AM (#4569898)
Yes, I'm aware of that. But my philosophy is to always try to conserve keystrokes wherever possible. Premature optimization is the root of all evil and all that. :) For the same reason I prefer to use dict.items() over dict.iteritems() and range() over xrange() and so on.
Re:Go Bloviations by slurgfest on Tuesday September 25, 2012 @09:42AM (#4570259)
This is a simple enough case that I'm not sure it matters, but I think the sum version is simpler to read. Generator expressions are quite powerful if you want to write Python which is more functional-flavored.
Re:Go Bloviations by rat87 on Tuesday September 25, 2012 @10:20AM (#4570439)
I disagree, I think filter/length models the meaning better.