[Tutor] rstrip in list?

bob gailer bgailer at gmail.com
Tue Feb 9 17:15:29 CET 2010

Ken G. wrote:
> I printed out some random numbers to a list and use 'print mylist' and
> they came out like this:
> ['102\n', '231\n', '463\n', '487\n', '555\n', '961\n']
> I was using 'print mylist.rstrip()' to strip off the '\n'
> but kept getting an error of :
> AttributeError: 'list' object has no attribute 'rstrip'

rstrip is a string method, not a list method. You must apply it to each 
element in the list. One way is:

print [item.rstrip() for iten in mylist]

Bob Gailer
Chapel Hill NC

More information about the Tutor mailing list