string to list conversion

MRAB google at mrabarnett.plus.com
Thu Feb 19 08:09:53 EST 2009


John Forse wrote:
> I need to convert an input string say 'xxxx' to a list of the form 
> ['xxxx' ,]. If I use list(stringname), I get ['x','x','x','x'] ; 
> list.join() is an error;  and str.join() won't use lists. I do need the 
> comma after the string. Is there a simple solution?
> 
Have you tried [stringname], eg ['xxxx' ,]? :-)

Why do you need the comma? Python permits it but it isn't necessary:

 >>> ['xxxx' ,]
['xxxx']



More information about the Python-list mailing list