The REALLY bad thing about Python lists ..

Russell Wallace rwallace at esatclear.ie
Wed May 24 22:16:57 EDT 2000


Greg Ewing wrote:
> I'd much rather have an honest, well-defined "wrap around"
> operator that I can rely on, even if I have to look up the
> language definition now and then, than have to wade through
> code that's been obfuscated to work around its absence.

So define one.

def wrapmod(x, y):
	while x < 0:
		x = x + y    # simple implementation, could do it more efficiently
	return x % y

IMO this isn't a sufficiently common thing to warrant an extra operator;
and having two integer mod operators is very likely to lead to people
using the wrong one.

-- 
"To summarize the summary of the summary: people are a problem."
Russell Wallace
mailto:rwallace at esatclear.ie
http://www.esatclear.ie/~rwallace



More information about the Python-list mailing list