On Tue, Feb 9, 2010 at 10:28 AM, Ken G. <beach...@insightbb.com> 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']

How are you generating this list? You should be able to create it
without the \n. That would be better than stripping them out.

> 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?

Use a list comprehension or map():

In [1]: l = ['102\n', '231\n', '463\n', '487\n', '555\n', '961\n']

In [2]: [ i.rstrip() for i in l ]
Out[2]: ['102', '231', '463', '487', '555', '961']

In [3]: map(str.rstrip, l)
Out[3]: ['102', '231', '463', '487', '555', '961']

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

Reply via email to