On May 9, 6:13 am, Steven D'Aprano <st...@remove-this- cybersource.com.au> wrote: > On Sat, 08 May 2010 13:46:59 -0700, Mark Dickinson wrote: > >> However, s[:-len(t)] should be both faster and correct. > > > Unless len(t) == 0, surely? > > Doh! The hazards of insufficient testing. Thanks for catching that.
I have a love-hate relationship with the negative index semantics for exactly this reason: code like 'x[-n]' always seems smelly to me. It's often not what the code author actually wanted, except when n is guaranteed strictly positive for some reason. 'x[-1]' is fine, of course. -- Mark -- http://mail.python.org/mailman/listinfo/python-list