[Tutor] Noob question

Eric Brunson brunson at brunson.com
Sun Dec 9 19:52:09 CET 2007


quantrum75 wrote:
> Hi there,
> I am a newbie trying to actively learn python.
> My question is,
> Suppose I have a list
> a=["apple","orange","banana"]
>
> How do I convert this list into a string which is
>
> b="appleorangebanana"
> Sorry for my ignorance, 

No worries, every new language has its idioms that only come from 
experience and exposure.

Try this:

In [1]: a=["apple","orange","banana"]

In [2]: print "".join( a )
appleorangebanana

And just for clarity:

In [3]: print "|".join( a )
apple|orange|banana

Hope that helps, good luck learning python.

Sincerely,
e.

> but I have been trying a "for" loop and trying the inbuilt str.join() 
> method without success.
> Thanks a lot.
> Regards
> Quant
>
> ------------------------------------------------------------------------
> Looking for last minute shopping deals? Find them fast with Yahoo! 
> Search. 
> <http://us.rd.yahoo.com/evt=51734/*http://tools.search.yahoo.com/newsearch/category.php?category=shopping> 
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   



More information about the Tutor mailing list