stripping parts of elements in a list

Paul Rubin http
Sat Oct 28 14:05:33 EDT 2006


"CSUIDL PROGRAMMEr" <syedamjad_a at yahoo.com> writes:
> ['amjad\n', 'kiki\n', 'jijiji\n']
> I am trying to  get rid of '\n' after each name.
>  to get list as
> ['amjad','kiki','jijiji']
> 
> But list does not have a strip function as string does have.
> 
> is there any solutions

a = ['amjad\n', 'kiki\n', 'jijiji\n']

b = [x.strip() for x in a]

print b



More information about the Python-list mailing list