2008/8/17 Alexnb <[EMAIL PROTECTED]> > > Basically I want the code to be able to pick out how many strings there are > and then do something with each, or the number. When I say string I mean > how > many "strings" are in the string "string string string non-string string" > > Does that help? > > Not quite sure, if i underestand the task you want to achieve correctly, but do you maybe mean something like the following? (here under "string" the exact wording "string" is meant; obviously any section of the input string will be a string too)
>>> fun_string = "string string string non-string non-string string" >>> fun_words = fun_string.split() >>> fun_words ['string', 'string', 'string', 'non-string', 'non-string', 'string'] >>> strings_from_fun_words = [word for word in fun_words if word == "string"] >>> strings_from_fun_words ['string', 'string', 'string', 'string'] >>> len(fun_words) 6 >>> len(strings_from_fun_words) 4 >>> HTH Vlasta
-- http://mail.python.org/mailman/listinfo/python-list