On 2023-03-15 17:09:52 +0000, Weatherby,Gerard wrote: > Sum is faster than iteration in the general case.
I'd say this is the special case, not the general case. > def sum1(): > s = 0 > for i in range(1000000): > s += i > return s > > def sum2(): > return sum(range(1000000)) Here you already have the numbers you want to add. The OP needed to compute those numbers first. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | h...@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!"
signature.asc
Description: PGP signature
-- https://mail.python.org/mailman/listinfo/python-list