String to sequence

Vlastimil Brom vlastimil.brom at gmail.com
Sat Mar 14 10:30:43 CET 2009


2009/3/14 mattia <gervaz at gmail.com>:
> How can I convert the following string:
>
> 'AAR','ABZ','AGA','AHO','ALC','LEI','AOC',
> EGC','SXF','BZR','BIQ','BLL','BHX','BLQ'
>
> into this sequence:
>
> ['AAR','ABZ','AGA','AHO','ALC','LEI','AOC',
> EGC','SXF','BZR','BIQ','BLL','BHX','BLQ']
>
> Thanks a lot,
> Mattia
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Apart from the "obvious" and rather discouraged
>>> list(eval("'AAR','ABZ','AGA','AHO'"))
['AAR', 'ABZ', 'AGA', 'AHO']

you may try e.g.:

>>> [item[1:-1] for item in "'AAR','ABZ','AGA','AHO'".split(",")]
['AAR', 'ABZ', 'AGA', 'AHO']

hth,
  vbr



More information about the Python-list mailing list