3 ms·
Sure, but it's less expensive to store and maintain a single boolean value than a potentially-huge list. That's sort of the point of any(), sum(), or any other
by jessaustin 14y ago
Sure, but it's less expensive to store and maintain a single boolean value than a potentially-huge list. That's sort of the point of any(), sum(), or any other builtin that takes an iterable. This reminds me of reduce functions in MapReduce: if they return variable-sized objects they'll blow up.
As others suggest I'm probably all wet about savings vs. a simple loop because of instantiation etc. And I don't think I'd ever use expressions like these merely for their side effects. I do expect that at a certain problem size the cumulative costs of building the list in a list comp will swamp the generator instantiation costs of gen exps consumed by iterator-friendly functions.