Converstion
John Machin
sjmachin at lexicon.net
Fri Apr 28 16:55:20 EDT 2006
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.
More information about the Python-list
mailing list