[Tutor] Converting a list to a string
Praveen Pathiyil
ppathiyi@cisco.com
Mon, 7 May 2001 16:40:34 +0530
This is a multi-part message in MIME format.
------=_NextPart_000_0169_01C0D714.7021E080
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Thanks Glen and Remco.
That would definitely serve my purpose.
Regards,
Praveen.
----- Original Message -----=20
From: Glen Wheeler=20
To: Praveen Pathiyil ; tutor@python.org=20
Sent: Monday, May 07, 2001 4:29 PM
Subject: Re: [Tutor] Converting a list to a string
I think you want to have a look at string.join().
For example...
>>> import string
>>> x =3D ['I', 'am', 'a', 'string']
>>> string.join(x)
'I am a string'
You can also specify the separating character as well, with a second =
argument. Like...
>>> x =3D ['W', 'o', 'r', 'd']
>>> string.join(x, '')
'Word'
Hope that helps,
Glen.
----- Original Message -----=20
From: Praveen Pathiyil=20
To: tutor@python.org=20
Sent: Monday, May 07, 2001 8:53 PM
Subject: [Tutor] Converting a list to a string
Hi all,
=20
If i have a list=20
status =3D ['tftp>', 'Sent', '1943', 'bytes', 'in', '0.0', =
'seconds'],
is there a single command which will give me a string=20
tftp> Sent 1943 bytes in 0.0 seconds
OR do i have to do=20
stat_str =3D ''
for elt in status:
stat_str =3D stat_str + ' ' + elt
TIA,
Praveen.
------=_NextPart_000_0169_01C0D714.7021E080
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3103.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Thanks Glen and Remco.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>That would definitely serve my=20
purpose.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Regards,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Praveen.</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV=20
style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
<A href=3D"mailto:wheelege@tsn.cc" title=3Dwheelege@tsn.cc>Glen =
Wheeler</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
href=3D"mailto:ppathiyi@cisco.com"=20
title=3Dppathiyi@cisco.com>Praveen Pathiyil</A> ; <A=20
href=3D"mailto:tutor@python.org" =
title=3Dtutor@python.org>tutor@python.org</A>=20
</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Monday, May 07, 2001 4:29 =
PM</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: [Tutor] Converting =
a list to=20
a string</DIV>
<DIV><BR></DIV>
<DIV> </DIV>
<DIV> I think you want to have a look at string.join().</DIV>
<DIV> </DIV>
<DIV> For example...</DIV>
<DIV> </DIV>
<DIV>>>> import string</DIV>
<DIV>>>> x =3D ['I', 'am', 'a', 'string']<BR>>>>=20
string.join(x)<BR>'I am a string'</DIV>
<DIV> </DIV>
<DIV> You can also specify the separating character as well, =
with a=20
second argument. Like...</DIV>
<DIV> </DIV>
<DIV>>>> x =3D ['W', 'o', 'r', 'd']<BR>>>> =
string.join(x,=20
'')<BR>'Word'</DIV>
<DIV> </DIV>
<DIV> Hope that helps,</DIV>
<DIV> Glen.</DIV>
<DIV> </DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; =
MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
<DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV=20
style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
<A href=3D"mailto:ppathiyi@cisco.com" =
title=3Dppathiyi@cisco.com>Praveen=20
Pathiyil</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
href=3D"mailto:tutor@python.org"=20
title=3Dtutor@python.org>tutor@python.org</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Monday, May 07, 2001 =
8:53=20
PM</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Tutor] Converting a =
list to a=20
string</DIV>
<DIV><BR></DIV>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>If i have a list </FONT><FONT =
face=3DArial=20
size=3D2></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>status =3D ['tftp>', 'Sent', =
'1943', 'bytes',=20
'in', '0.0', 'seconds'],</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>is there a single command which =
will give me a=20
string </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>tftp> Sent 1943 bytes in 0.0=20
seconds</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>OR <FONT face=3DArial size=3D2>do i =
have to do=20
</FONT></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>stat_str =3D ''</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>for elt in status:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> <FONT =
face=3DArial=20
size=3D2>stat_str =3D <FONT face=3DArial size=3D2>stat_str + ' ' +=20
elt</FONT></FONT></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>TIA,</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>Praveen.</FONT></DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_0169_01C0D714.7021E080--