Re: strip char from list of strings

2009-05-19 Thread alex23
On May 20, 12:55 am, Laurent Luce wrote: > I had a simple loop stripping each string but I was looking for > something concise and efficient. I like the following answer: > x = [s.rstrip('\n') for s in x] Your initial requirement stated that you needed this to happen in- place. What you're doing

Re: strip char from list of strings

2009-05-19 Thread Jorgen Grahn
On Tue, 19 May 2009 10:25:35 +0200, Piet van Oostrum wrote: >> Laurent Luce (LL) wrote: > >>LL> I have the following list: > >>LL> [ 'test\n', test2\n', 'test3\n' ] > >>LL> I want to remove the '\n' from each string in place, what is the >>LL> most efficient way to do that ? > > I suppose yo

Re: strip char from list of strings

2009-05-19 Thread Laurent Luce
Thanks Casey. I like your solution. Casey Webster wrote: > On May 18, 3:30 pm, Laurent Luce 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, >> >>

Re: strip char from list of strings

2009-05-19 Thread Laurent Luce
I had a simple loop stripping each string but I was looking for something concise and efficient. I like the following answer: x = [s.rstrip('\n') for s in x] David Stanek wrote: > On Mon, May 18, 2009 at 3:30 PM, Laurent Luce wrote: >> I have the following list: >> >> [ 'test\n', test2\n', 'test3

Re: strip char from list of strings

2009-05-19 Thread Casey Webster
On May 18, 3:30 pm, Laurent Luce 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 Do you _really_ need to do this in place? If not, the simple

Re: strip char from list of strings

2009-05-19 Thread Piet van Oostrum
> Laurent Luce (LL) wrote: >LL> I have the following list: >LL> [ 'test\n', test2\n', 'test3\n' ] >LL> I want to remove the '\n' from each string in place, what is the >LL> most efficient way to do that ? I suppose you mean you have lists similar to the one given because with a list of 3

Re: strip char from list of strings

2009-05-19 Thread Jeremiah Dodds
On Mon, May 18, 2009 at 8:30 PM, Laurent Luce 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/p

Re: strip char from list of strings

2009-05-19 Thread David Stanek
On Mon, May 18, 2009 at 3:30 PM, Laurent Luce 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 ? > What have you tried so far? -- David blog: http://www.traceback.org

strip char from list of strings

2009-05-19 Thread Laurent Luce
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