Function/method returning list of chars in string?

Diez B. Roggisch deets at nospam.web.de
Tue Jun 9 03:32:50 EDT 2009


Hendrik van Rooyen schrieb:
> One can go from lb = ['b','a','n','a','n','a']
> to s = "banana" by using s = "".join(lb)
> 
> Is there a way to go the reverse route?
> 
> I have not been able to find one.
> 
> It is obviously easy to write a for char in s loop
> or list comprehension, but there seems to be
> no function or string method to return a list
> of characters.
> 
> using lb = s.split("") would have been nice
> as a complement to s = "".join(lb).
> 
> Split is already full of magic, it could do with more.


I think

lb = list(s)

is good enough.

Diez



More information about the Python-list mailing list