[Tutor] writing list elements into a string

John Fouhy john at fouhy.net
Thu Dec 15 21:42:45 CET 2005


On 16/12/05, ps python <ps_python3 at yahoo.co.in> wrote:
> >>> a  = ['apple','is','a','good','fruit']
> >>> ab =''
> >>> for m in a:
>         k = ''.join(m)
>         ab.join(k)

You're almost there...

>>> a = ['apple', 'is', 'a', 'good', 'fruit']
>>> ' '.join(a)
'apple is a good fruit'
>>> '...'.join(a)
'apple...is...a...good...fruit'
>>> '\n'.join(a)
'apple\nis\na\ngood\nfruit'
>>> print '\n'.join(a)
apple
is
a
good
fruit

HTH!

--
John.


More information about the Tutor mailing list