[Tutor] rstrip in list?

Robert Berman bermanrl at cfl.rr.com
Tue Feb 9 17:15:33 CET 2010



-----Original Message-----
From: tutor-bounces+bermanrl=cfl.rr.com at python.org
[mailto:tutor-bounces+bermanrl=cfl.rr.com at python.org] On Behalf Of Ken G.
Sent: Tuesday, February 09, 2010 10:29 AM
To: tutor at python.org
Subject: [Tutor] rstrip in list?

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'

My memory must be hazy but I thought I had it working several months ago.

Any idea or suggestion?

TIA, Ken

In [14]: mylist
Out[14]: ['102\n', '231\n', '463\n', '487\n', '555\n', '961\n']

In [15]: for item in mylist:
   ....:     print item.strip('\n')
   ....:
   ....:
102
231
463
487
555
961


I get the impression you can strip something from the elements in the list,
but that it balks at a change to the  entire list in a single statement?


Robert 
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list