
12.07.18 17:30, Paul Moore пише:
I'm -1 on having inefficient versions like your primes(n) implementation above in the stdlib. People will use them not realising they may not be suitable for anything other than toy problems.
This is just the shortest version that I write every time when I need primes. For the stdlib implementation we don't have such strong limit on the size.
Your divide_and_round might be nice, but there are multiple common ways of rounding 0.5 (up, down, towards 0, away from 0, to even, to odd, ...) Your implementation does round to even, but that's not necessarily the obvious one (schools often teach round up or down, so use of your implementation in education could be confusing).
This is the one that is useful in many applications and can't be trivially written as expression in Python, but is useful in many applications (date and time, Fraction, Decimal). Divide and rounding down: n//m. Divide and rounding up: (n+m-1)//m or -((-n)//m).