Re: find all index positions

2006-05-12 Thread John Machin
On 13/05/2006 1:55 AM, vbgunz wrote: > I forgot to explain my reason for over shadowing the 'string' built-in > within my iterator. To me, it doesn't matter because the string > identifier is temporary within the function and dies when the function > dies. Also, I personally don't use the string fu

Re: find all index positions

2006-05-12 Thread John Machin
On 13/05/2006 1:45 AM, vbgunz wrote: > Hello John, > > Thank you very much for your pointers! I decided to redo it and try to > implement your suggestion. I think I did a fair job and because of your > suggestion have a better iterator. Thank you! > > def indexer(string, substring, overlap=1): >

Re: find all index positions

2006-05-12 Thread vbgunz
I forgot to explain my reason for over shadowing the 'string' built-in within my iterator. To me, it doesn't matter because the string identifier is temporary within the function and dies when the function dies. Also, I personally don't use the string function and prefer ''.join('hi'), etc. Also, a

Re: find all index positions

2006-05-12 Thread vbgunz
Hello John, Thank you very much for your pointers! I decided to redo it and try to implement your suggestion. I think I did a fair job and because of your suggestion have a better iterator. Thank you! def indexer(string, substring, overlap=1): '''indexer(string, substring, [overlap=1]) -> int

Re: find all index positions

2006-05-11 Thread John Machin
On 12/05/2006 5:13 AM, vbgunz wrote: > I thought this to be a great exercise so I went the extra length to > turn it into a function for my little but growing library. I hope you > enjoy :) > Oh, indeed ;-) > > def indexer(string, target): Consider not shadowing the name of the string module.

Re: find all index positions

2006-05-11 Thread alisonken1
Scott David Daniels wrote: > [EMAIL PROTECTED] wrote: > print list(positions('1234', 'abcd efgd 1234 fsdf gfds abcde 1234')) > > prints: > [10, 31] > Nicer than mine ;) Shows I need to get a job where I use python more! -- http://mail.python.org/mailman/listinfo/python-list

Re: find all index positions

2006-05-11 Thread vbgunz
I thought this to be a great exercise so I went the extra length to turn it into a function for my little but growing library. I hope you enjoy :) def indexer(string, target): '''indexer(string, target) -> [list of target indexes] enter in a string and a target and indexer will either re

Re: find all index positions

2006-05-11 Thread Gary Herron
Paul Rubin wrote: >[EMAIL PROTECTED] writes: > > >>say i have string like this >>astring = 'abcd efgd 1234 fsdf gfds abcde 1234' >>if i want to find which postion is 1234, how can i achieve this...? i >>want to use index() but it only give me the first occurence. I want to >>know the positions o

Re: find all index positions

2006-05-11 Thread Gary Herron
[EMAIL PROTECTED] wrote: >hi >say i have string like this >astring = 'abcd efgd 1234 fsdf gfds abcde 1234' >if i want to find which postion is 1234, how can i achieve this...? i >want to use index() but it only give me the first occurence. I want to >know the positions of both "1234" >thanks > >

Re: find all index positions

2006-05-11 Thread Paul Rubin
[EMAIL PROTECTED] writes: > say i have string like this > astring = 'abcd efgd 1234 fsdf gfds abcde 1234' > if i want to find which postion is 1234, how can i achieve this...? i > want to use index() but it only give me the first occurence. I want to > know the positions of both "1234" Most straig

Re: find all index positions

2006-05-11 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > astring = 'abcd efgd 1234 fsdf gfds abcde 1234' > i want to find all positions of '1234' in astring. def positions(target, source): '''Produce all positions of target in source''' pos = -1 try: while True: po

Re: find all index positions

2006-05-11 Thread Peter Otten
alisonken1 wrote: > == > def getAllIndex(aString=None, aSub=None): > t=dict() > c=0 > ndx=0 > while True: > try: > ndx=aString.index(aSub, ndx) > t[c]=ndx > ndx += 1 > c += 1 > except ValueError: >

Re: find all index positions

2006-05-11 Thread alisonken1
[EMAIL PROTECTED] wrote: > hi > say i have string like this > astring = 'abcd efgd 1234 fsdf gfds abcde 1234' > if i want to find which postion is 1234, how can i achieve this...? i > want to use index() but it only give me the first occurence. I want to > know the positions of both "1234" > thank

Re: find all index positions

2006-05-11 Thread Tim Chase
> say i have string like this > astring = 'abcd efgd 1234 fsdf gfds abcde 1234' > if i want to find which postion is 1234, how can i > achieve this...? i want to use index() but it only give > me the first occurence. I want to know the positions of > both "1234" Well, I'm not sure how efficient it