how to remove \n in the list

alex23 wuwei23 at gmail.com
Tue Apr 15 20:12:03 EDT 2008


On Apr 16, 9:26 am, Yves Dorfsman <y... at zioup.com> wrote:
> If we do:
> lines[:] = [line.rstrip('\n') for line in lines]
>
> We reuse an existing list, therefore we are saving the time it takes to
> create a new list ? So this is a performance issue ?

I think it's more of a reference issue. You may have other labels
already pointing to 'lines', if you want them to refer to the same,
rstrip'd list, you'd do an in-place update like this.

- alex23



More information about the Python-list mailing list