how to remove \n in the list

Kam-Hung Soh kamhung.soh at gmail.com
Mon Apr 14 02:12:41 EDT 2008


On Apr 14, 2:58 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Mon, 14 Apr 2008 01:41:55 -0300, reetesh nigam
> <nigamreetes... at gmail.com> escribió:
>
> > hi,
> > l=['5\n', '2\n', '7\n', '3\n', '6\n']
>
> > how to remove \n from the given list
>
> l is is very poor name... I'll use lines instead:
>
> lines[:] = [line.rstrip('\n') for line in lines]
>
> --
> Gabriel Genellina

Also: map(str.rstrip, l)

--
Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</
a>



More information about the Python-list mailing list