[Tutor] Converting a list to a string
Remco Gerlich
scarblac@pino.selwerd.nl
Mon, 7 May 2001 12:58:42 +0200
On 0, Praveen Pathiyil <ppathiyi@cisco.com> wrote:
> Hi all,
>
> If i have a list
> status = ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', 'seconds'],
> is there a single command which will give me a string
> tftp> Sent 1943 bytes in 0.0 seconds
>
> OR do i have to do
>
> stat_str = ''
> for elt in status:
> stat_str = stat_str + ' ' + elt
import string
print string.join(status) # If you want something other than a space,
# give it as second argument.
In new versions you can also spell that
" ".join(status) # Join list 'status' with spaces in between
--
Remco Gerlich