splitting a long string into a list
sjmachin at lexicon.net
Tue Nov 28 08:50:54 CET 2006
> 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,
[snip most of VERY long string]
> Book);Corporate Reform, Personhood, Farming (Dem. Book);Crime Rates,
> Legislation, Education;Debt, Credit Cards;'
As far as I recall, without digging in the archives:
We would probably agree (if shown the schema) that the database wasn't
designed. However it seems to have changed. Last time you asked, it
was at least queryable and producing rows, each containing one column
(a string of structure unknown to us and not divulged by you). You were
given extensive advice: how to use split(), plus some questions to
answer about the data e.g. the significance (if any) of semicolon
versus comma. You were also asked about the SQL that was used. You were
asked to explain what you meant by "keywords". All of those questions
were asked so that we could understand your problem, and help you.
Since then, nothing.
Now you have what appears to be something like your previous results
stripped of newlines and smashed together (are the newlines of no
significance at all?), and you appear to be presenting it as a new
What's going on?
More information about the Python-list