like a "for loop" for a string
ptmcg at austin.rr.com
Mon Aug 18 17:14:52 CEST 2008
On Aug 17, 3:12 pm, Alexnb <alexnbr... at gmail.com> wrote:
> Uhm, "string" and "non-string" are just that, words within the string. Here
> shall I dumb it down for you?
> string = "yes text1 yes text2 yes text3 no text4 yes text5+more Text yes
> text6 no text7 yes text8"
> It doesn't matter what is in the string, I want to be able to know exactly
> how many "yes"'s there are.
> I also want to know what is after each, regardless of length. So, I want to
> be able to get "text1", but not "text4" because it is after "no" and I want
> all of "text5+more Text" because it is after "yes". It is like the yeses are
> bullet points and I want all the info after them. However, all in one
> Fredrik Lundh wrote:
> > Alexnb wrote:
> >> 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 really, since you haven't defined what "string" and "non-string" are
> > or how strings are separated from each other, and, for some odd
> > reason, refuse to provide an actual example that includes both a proper
> > sample string *and* the output you'd expect.
> > please don't use the mailing list to play 20 questions.
> > </F>
> > --
> View this message in context:http://www.nabble.com/like-a-%22for-loop%22-for-a-string-tp19022098p1...
> Sent from the Python - python-list mailing list archive at Nabble.com.- Hide quoted text -
> - Show quoted text -
Well, in "dumbing" this down, I think you actually put a little more
thought into your explanation. If you break this up at the "yes"
string = "yes text1 yes text2 yes text3 no text4 yes text5+more Text
yes text6 no text7 yes text8"
Would this not generate:
yes text3 no text4
yes text5+more Text
yes text6 no text7
So your output *would* return "text4" and "text7", but buried within
the body indicated by the previous "yes".
Or is "no" supposed to be some kind of suppression trigger? Should
"no" turn OFF matching until another "yes" is found? Gee, I guess I
didn't read anything like that in your original post.
Please dumb this down some more, so we can figure out just what the
heck you mean. (And I can't wait to go to a customer to do
requirements analysis, and just tell them we need to "dumb things
down" for them!)
More information about the Python-list