splitting a long string into a list
timr at probo.com
Tue Nov 28 08:39:00 CET 2006
"ronrsr" <ronrsr at gmail.com> wrote:
>I have a single long string - I'd like to split it into a list of
>unique keywords. Sadly, the database wasn't designed to do this, so I
>must do this in Python - I'm having some trouble using the .split()
>function, it doesn't seem to do what I want it to - any ideas?
>thanks very much for your help.
>longstring = 'Agricultural subsidies; Foreign aidAgriculture;
>Sustainable Agriculture - Support; Organic Agriculture; Pesticides, US,
>Childhood Development, Birth Defects; Toxic ChemicalsAntibiotics,
>AnimalsAgricultural Subsidies, Global TradeAgricultural
What do you want out of this? It looks like there are several levels
crammed together here. At first blush, it looks like topics separated by
"; ", so this should get you started:
topics = longstring.split("; ")
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list