ronrsr wrote: > still having a heckuva time with this. > > here's where it stand - the split function doesn't seem to work the way > i expect it to. > > > longkw1,type(longkw): Agricultural subsidies; Foreign > aid;Agriculture; Sustainable Agriculture - Support; Organic > Agriculture; Pesticides, US, Childhood Development, Birth Defects; > <type 'list'> 1 > > longkw.replace(',',';') > > Agricultural subsidies; Foreign aid;Agriculture; Sustainable > Agriculture - Support; Organic Agriculture; Pesticides, US, Childhood > Development > > > kw = longkw.split("; ,") #kw is now a list of len 1 > > kw,typekw= ['Agricultural subsidies; Foreign aid;Agriculture; > Sustainable Agriculture - Support; Organic Agriculture; Pesticides, US, > Childhood Development, Birth Defects; Toxic Chemicals;Antibiotics, > Animals;Agricultural Subsidies > > > what I would like is to break the string into a list of the delimited > words, but have had no luck doing that - I thought split wuld do that, > but it doens't. > > bests, > > -rsr- > > >
>>> import SE # http://cheeseshop.python.org/pypi/SE/2.3 >>> Split_Marker = SE.SE (' ,=| ;=| ') # Translates both ',' and ';' into an arbitrary split mark ('|') >>> for item in Split_Marker (longstring).split ('|'): print item Agricultural subsidies Foreign aidAgriculture Sustainable Agriculture - Support Organic Agriculture ... etc. To get rid of the the leading space on some lines simply add corresponding replacements. SE does any number of substitutions in one pass. Defining them is a simple matter of writing them up in one single string from which the translator object is made: >>> Split_Marker = SE.SE (' ,=| ;=| ", =|" "; =|" ') >>> for item in Split_Marker (longstring).split ('|'): print item Agricultural subsidies Foreign aidAgriculture Sustainable Agriculture - Support Organic Agriculture Regards Frederic -- http://mail.python.org/mailman/listinfo/python-list