A suggestion for a possible Python module
staschuk at telusplanet.net
Wed Mar 5 20:02:16 CET 2003
Quoth Jp Calderone:
> For the first part,
> s[i:j:k] = whatever
> is the same as
> s.__setitem__(slice(i, j, k), whatever)
> so it's legal, syntatically, but only works if the invoked __setitem__
> implementation actually implements it sensibly.
> I can't think of any real use cases for it either, though.
Erastothenes' sieve comes to mind.
numbers = range(2, n)
zeroes = *len(numbers)
primes = 
for i in range(len(numbers)):
prime = numbers[i]
numbers[i::prime] = zeroes[i::prime]
# primes is now a list of primes in [2, n)
Steven Taschuk Aral: "Confusion to the enemy, boy."
staschuk at telusplanet.net Mark: "Turn-about is fair play, sir."
(_Mirror Dance_, Lois McMaster Bujold)
More information about the Python-list