3 ms·
But you only ever need to unwrap one sum(). And with sequence comprehensions, what you get instead is sum(... for ... if ... for ... if ...) - I don't think tha
by int_19h 5y ago
But you only ever need to unwrap one sum(). And with sequence comprehensions, what you get instead is sum(... for ... if ... for ... if ...) - I don't think that's improved by rewriting it as (...).sum().
- XorNot 5y agoThere's a not unreasonable position implicit in Python's way that the "most significant" operation should be most visible. The problem with filter chaining is the final assignment and the actual value are separated by the rest of the chain. i.e. x = strList.filter(parseInt).sum() doesn't tell me what type x is till I read the whole line. Whereas: x = sum( parseInt(v) for v in strList ) tells me as quickly as possible that I'm dealing with a single value output that will be a sum.