list manipulation

Vlastimil Brom vlastimil.brom at gmail.com
Tue Apr 22 23:13:39 CEST 2008


2008/4/22, DataSmash <rdh at new.rr.com>:
>
> Hello,
>
> I have a list that looks like this:
> roadList = ["Motorways","Local","Arterial"]
>
> I want to apply some code so that the output looks like this:
> "Motorways;Local;Arterial"
>
> ...in other words, I want each item in the list separated by a ';' and
> then the whole thing surrounded by quotes.
>
> How can this be done with the LEAST amount of code?
>
> I appreciate your help!
> R.D.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Maybe
>>> ";".join(["Motorways","Local","Arterial"])
'Motorways;Local;Arterial'
or
>>> '"'+";".join(["Motorways","Local","Arterial"])+'"'
'"Motorways;Local;Arterial"'

if you really want the quotes to be a part of the string.

vbr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080422/c68b3426/attachment.html>


More information about the Python-list mailing list