Help for Python newbie

Pitre, Bill J bj.pitre at pnl.gov
Thu Jun 14 22:55:02 EDT 2001


To preserve "mylist" as is, but print out it values, you could do this:

>>> import string
>>> mylist = ['1', '2', '3']
>>> print '\t'.join(mylist)
1       2       3
>>> print mylist
['1', '2', '3']
>>> 


-----Original Message-----
From: Alex Martelli [mailto:aleaxit at yahoo.com]
Posted At: Tuesday, June 12, 2001 2:33 AM
Posted To: python
Conversation: Help for Python newbie
Subject: Re: Help for Python newbie


"Bob Hibberdine" <bob.hibberdine at ntlworld.com> wrote in message
news:zSkV6.18764$m4.73107 at news6-win.server.ntlworld.com...
    ...
> >>> import string
> >>> mylist = ['1','2','3']
> >>> mystring = ''
> >>> mystring = mystring.join(mylist)
> >>> print mystring
> 123
>
> note there is no space between the items.

Right: the separator is mystring, and mystring is empty,
so the separator is empty.  To use tab as the separator:

>>> mystring = '\t'
>>> mystring = mystring.join(mylist)
>>> print mystring
1    2    3

or, more simply, just:
>>> mystring = '\t'.join(mylist)


Alex


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20010614/3c3aec1f/attachment.html>


More information about the Python-list mailing list