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:
>
>
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
Paddy wrote:
> the del version - is that an optimisation?
> Is it actually faster?
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
the del version - is that an optimisation?
Is it actually faster?
- I did not have enough info. to check so just did what came naturally
to me :-)
- Pad.
--
http://mail.python.org/mailman/listinfo/python-list
On 28/04/2006 4:46 PM, Paddy wrote:
> Something like (untested):
>
> out = []
> for ch in instring:
> if ch==backspace:
> if out:
> out = out[:-1]
> else:
> out.append(ch)
> outstring = ''.join(out)
Instead of:
if out:
out = out[:-1]
consider:
del out[-1:]
--
Something like (untested):
out = []
for ch in instring:
if ch==backspace:
if out:
out = out[:-1]
else:
out.append(ch)
outstring = ''.join(out)
- Pad.
--
http://mail.python.org/mailman/listinfo/python-list
On 28/04/2006 9:50 AM, Chris wrote:
> In a program I'm writing I have a problem where a bit of text sent over
> a network arrives at my server. If the person who sent the text made a
> mistake typing the word and pressed backspace the backspace code is
> included in the word for example hello is he
Chris wrote:
> In a program I'm writing I have a problem where a bit of text sent over
> a network arrives at my server. If the person who sent the text made a
> mistake typing the word and pressed backspace the backspace code is
> included in the word for example hello is hel\x08lo. The \x08 is t
In a program I'm writing I have a problem where a bit of text sent over
a network arrives at my server. If the person who sent the text made a
mistake typing the word and pressed backspace the backspace code is
included in the word for example hello is hel\x08lo. The \x08 is the
backspace key. How