Re: like a "for loop" for a string

2008-08-18 Thread bearophileHUGS
Fredrik Lundh: > or you could use re.finditer, which can be used for a lot more than just > splitting. Having implemented some of them (and even invented algorithms like a new substring search, that I have appreciated) you know that string methods are simpler ways to efficiently perform specialize

Re: like a "for loop" for a string

2008-08-18 Thread Paul McGuire
On Aug 17, 3:12 pm, Alexnb <[EMAIL PROTECTED]> 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

Re: like a "for loop" for a string

2008-08-18 Thread Boris Borcic
Alexnb 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

Re: like a "for loop" for a string

2008-08-18 Thread Fredrik Lundh
Wojtek Walczak wrote: Got no idea, but it might be a nice try. It should be a quite good memory saver for very large strings. or you could use re.finditer, which can be used for a lot more than just splitting. -- http://mail.python.org/mailman/listinfo/python-list

Re: like a "for loop" for a string

2008-08-18 Thread B
Mensanator wrote: On Aug 17, 6:03�pm, B <[EMAIL PROTECTED]> wrote: Alexnb 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

Re: like a "for loop" for a string

2008-08-17 Thread Mensanator
On Aug 17, 6:03�pm, B <[EMAIL PROTECTED]> wrote: > Alexnb 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 d

Re: like a "for loop" for a string

2008-08-17 Thread Wojtek Walczak
On Sun, 17 Aug 2008 12:07:45 -0700 (PDT), [EMAIL PROTECTED] wrote: > I'm waiting for a str.xsplit still :-) > If I write and submit a C implementation of xsplit how many chances do > I have to see it included into Python? :-) Got no idea, but it might be a nice try. It should be a quite good memo

Re: like a "for loop" for a string

2008-08-17 Thread B
Alexnb 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 exactl

Re: like a "for loop" for a string

2008-08-17 Thread bearophileHUGS
MRAB: > If it was introduced into Python v3.x then wouldn't it have to be > called str.split in order to be consistent with xrange -> range? :-) xsplit may be a name fit for Python 2.6/2.7. Regarding Python 3.0 you may be right, but then when you want the list of parts you have to do: list(somest

Re: like a "for loop" for a string

2008-08-17 Thread MRAB
On Aug 17, 8:40 pm, [EMAIL PROTECTED] wrote: > Eric Wertman: > > > So what exactly does that do?  Returns a generator, instead of a list? > > Allows you to iterate on the parts in a lazy way, without creating the > whole list of the pieces. > The arguments are the same of str.split(). > If it was i

Re: like a "for loop" for a string

2008-08-17 Thread Vlastimil Brom
Ok, after sending my post, I see, that the code got a bit screewed up, but morover, there should probably be a word boundary in the closing part of the regexp. A next attempt + added stripping the "yes" delimiter and the whitespace...: >>> import re >>> input_text = """yes text1 yes text2 yes text

Re: like a "for loop" for a string

2008-08-17 Thread mblume
Am Sun, 17 Aug 2008 13:12:36 -0700 schrieb Alexnb: > Uhm, "string" and "non-string" are just that, words within the string. > Here shall I dumb it down for you? > Please, bear with us. You are deep into the problem, we are not. It doesn't help to be rude. If you can explain your problem well, you

Re: like a "for loop" for a string

2008-08-17 Thread Vlastimil Brom
2008/8/17 Alexnb <[EMAIL PROTECTED]> > > 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 stri

Re: like a "for loop" for a string

2008-08-17 Thread Fredrik Lundh
Alexnb wrote: Uhm, "string" and "non-string" are just that, words within the string. From what I can tell, this is the first time you use the word "word" in your posts. > Here shall I dumb it down for you? No, you should do what you should have done from the very beginning: explain what y

Re: like a "for loop" for a string

2008-08-17 Thread Grzegorz Staniak
On 2008-08-17, Alexnb <[EMAIL PROTECTED]> wroted: > 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. - cut here - >>> import r

Re: like a "for loop" for a string

2008-08-17 Thread Paul Boddie
On 17 Aug, 20:22, Alexnb <[EMAIL PROTECTED]> wrote: > But I am wondering is there a way to something like this: > > funString = "string string string non-string non-string string" > and > for "string" in funString: > print something > > I know you can't do that; but, is there a way do do some

Re: like a "for loop" for a string

2008-08-17 Thread Alexnb
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"

Re: like a "for loop" for a string

2008-08-17 Thread Vlastimil Brom
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? > >

Re: like a "for loop" for a string

2008-08-17 Thread Grzegorz Staniak
On 2008-08-17, Alexnb <[EMAIL PROTECTED]> wroted: > Basically I want the code to be able to pick out how many strings What do you mean by "string"? foo = "abc abc cde abc ijk abc cde abc" "foo" is one "string". If you want substrings, specify what kind of substrings you mean. All occurences

Re: like a "for loop" for a string

2008-08-17 Thread Fredrik Lundh
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 def

Re: like a "for loop" for a string

2008-08-17 Thread bearophileHUGS
Eric Wertman: > So what exactly does that do? Returns a generator, instead of a list? Allows you to iterate on the parts in a lazy way, without creating the whole list of the pieces. The arguments are the same of str.split(). Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: like a "for loop" for a string

2008-08-17 Thread Alexnb
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? Fredrik Lundh wrote: > > Alexnb wrote: > >> Ya jus

Re: like a "for loop" for a string

2008-08-17 Thread Fredrik Lundh
Alexnb wrote: Ya just an example, to print the numbers 1-5 Sorry, I still don't have the slightest idea what you expect the code to do. But I am wondering is there a way to something like this: funString = "string string string non-string non-string string" and for "string" in funString:

Re: like a "for loop" for a string

2008-08-17 Thread Eric Wertman
So what exactly does that do? Returns a generator, instead of a list? > I'm waiting for a str.xsplit still :-) > If I write and submit a C implementation of xsplit how many chances do > I have to see it included into Python? :-) > > Bye, > bearophile > -- > http://mail.python.org/mailman/listinf

Re: like a "for loop" for a string

2008-08-17 Thread bearophileHUGS
Wojtek Walczak: > >>> somestr = "string1 string2 string3" > >>> for i in somestr.split(): > > ...print i > ... > string1 > string2 > string3 I'm waiting for a str.xsplit still :-) If I write and submit a C implementation of xsplit how many chances do I have to see it included into Python? :-)

Re: like a "for loop" for a string

2008-08-17 Thread Wojtek Walczak
On Sun, 17 Aug 2008 11:22:37 -0700 (PDT), Alexnb wrote: > funString = "string string string non-string non-string string" > and > for "string" in funString: > print something > > I know you can't do that; but, is there a way do do something similar that > gets the same result? What's "that"

Re: like a "for loop" for a string

2008-08-17 Thread Alexnb
Ya just an example, to print the numbers 1-5 Fredrik Lundh wrote: > > Alexnb wrote: > >> But I am wondering is there a way to something like this: >> >> funString = "string string string non-string non-string string" >> and >> for "string" in funString: >> print something >> >> I know

Re: like a "for loop" for a string

2008-08-17 Thread Colin J. Williams
Alexnb wrote: Okay, so lets say you have a list: funList = [1,2,3,4,5] and you do: for x in funList: print x this will print 1-5 But I am wondering is there a way to something like this: funString = "string string string non-string non-string string" and for "string" in funString:

Re: like a "for loop" for a string

2008-08-17 Thread Fredrik Lundh
Alexnb wrote: But I am wondering is there a way to something like this: funString = "string string string non-string non-string string" and for "string" in funString: print something I know you can't do that; but, is there a way do do something similar that gets the same result? you se

like a "for loop" for a string

2008-08-17 Thread Alexnb
Okay, so lets say you have a list: funList = [1,2,3,4,5] and you do: for x in funList: print x this will print 1-5 But I am wondering is there a way to something like this: funString = "string string string non-string non-string string" and for "string" in funString: print somethi