strip char from list of strings
Jeremiah Dodds
jeremiah.dodds at gmail.com
Tue May 19 04:09:49 EDT 2009
On Mon, May 18, 2009 at 8:30 PM, Laurent Luce <laurentluce49 at yahoo.com>wrote:
>
> I have the following list:
>
> [ 'test\n', test2\n', 'test3\n' ]
>
> I want to remove the '\n' from each string in place, what is the most
> efficient way to do that ?
>
> Regards,
>
> Laurent
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>>> s = [ 'test\n', test2\n', 'test3\n' ]
>>> [i.strip() for i in s]
['test', 'test2', 'test3']
>>> map(str.strip, s)
['test', 'test2', 'test3']
I'm not sure which one of these is more efficient, but it probably doesn't
really matter.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090519/ff968a40/attachment-0001.html>
More information about the Python-list
mailing list