<br><br><div class="gmail_quote">On Mon, May 18, 2009 at 8:30 PM, Laurent Luce <span dir="ltr"><<a href="mailto:laurentluce49@yahoo.com">laurentluce49@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
I have the following list:<br>
<br>
[ 'test\n', test2\n', 'test3\n' ]<br>
<br>
I want to remove the '\n' from each string in place, what is the most efficient way to do that ?<br>
<br>
Regards,<br>
<br>
Laurent<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><br>>>> s = [ 'test\n', test2\n', 'test3\n' ]<br>>>> [i.strip() for i in s]<br><br>['test', 'test2', 'test3']<br><br>>>> map(str.strip, s)<br>
<br>['test', 'test2', 'test3']<br><br><br>I'm not sure which one of these is more efficient, but it probably doesn't really matter. <br>