On 29/04/2006 2:22 AM, Edward Elliott wrote: > Peter Otten wrote: >> del x[-1:] # or del x[-1] if you are sure that len(x) > 0 >> just deletes the last item (if any) from x whereas >> x = x[:-1] >> copies all but the last item of the original list into a new one. This can >> take much longer: > > But his data is a string, which is immutable but heavily optimized:
Sorry, my mistake, I could have sworn it was a list: """ out = [] for ch in instring: if ch==backspace: if out: out = out[:-1] else: out.append(ch) outstring = ''.join(out) """ See that [] in the first line? That's what's confusing me. The out.append in the 2nd last line adds to the bogglement. -- http://mail.python.org/mailman/listinfo/python-list