string copy of a list
Alex Martelli
aleaxit at yahoo.com
Mon Apr 16 16:10:34 EDT 2001
"Jim Richardson" <warlock at eskimo.com> wrote in message
news:slrn9dk6ga.98l.warlock at gargoyle.myth...
> I am stumped, str(listname) returns a string of list, but includes the
commas
> and [] that the list would show if printed. I want a string copy of a
list, is
> there a simple way I have missed? please? thanks
What is each item in your list? If each item is a string, presumably what
you're asking for is to have all items joined -- either simply juxtaposed,
without separators, or maybe with (e.g.) a blank joining them? If so,
then the join method of string objects will perform either task:
juxtaposed = ''.join(listname)
blankjoined = ' '.join(listname)
If your list's items are NOT strings, you presumably want to make them
into strings before joining them. If str is acceptable for that:
juxtap1 = ''.join(map(str, listname))
etc. Or, you may use another function that "makes each of your items
into a string" more effectively, if there is one.
Alex
More information about the Python-list
mailing list