Re: [Tutor] FW: find() problem

2010-08-24 Thread Steven D'Aprano
On Wed, 25 Aug 2010 01:44:22 am Evert Rol wrote: > Why are you returning -1 here? > -1 is a valid list index. So? str.find() does the same thing. It guarantees to only return 0 or positive indexes if it finds the substring, and only returns -1 to indicate not found. -- Steven D'Aprano __

Re: [Tutor] FW: find() problem

2010-08-24 Thread Evert Rol
>>> I found it. >> >> Good. >> Few generic comments nonetheless, just for the fun of it ;-). >> >>> This one does the trick : >>> >>> def find(strng, ch, start, step=1): >>> index=start >>> while 0 <= index < len(strng): >>> if strng[index] == ch: >>> return index >>> index += step >>> return -

Re: [Tutor] FW: find() problem

2010-08-24 Thread Evert Rol
> I found it. Good. Few generic comments nonetheless, just for the fun of it ;-). > This one does the trick : > > def find(strng, ch, start, step=1): > index=start > while 0 <= index < len(strng): > if strng[index] == ch: > return index > index += step >

Re: [Tutor] FW: find() problem

2010-08-24 Thread Roelof Wobben
letter , "komt", aantal , "maal voor in het woord", fruit Roelof > Subject: Re: [Tutor] FW: find() problem > From: evert@gmail.com > Date: Tue, 24 Aug 2010 17:44:22 +0200 > CC: tutor@python.org > To: rwob...@hotmail.com > > > > > > > d

Re: [Tutor] FW: find() problem

2010-08-24 Thread Evert Rol
> > > > > def find(strng, ch, start, step=1): > > > > > index = start > > > > The problem lies here, if you do a print on index, it never gets past > > > > the first index of the number, so > > > > your while loop below goes into an infinite loop. > > > > > > > > For example: > > > > find('starfru

Re: [Tutor] FW: find() problem

2010-08-24 Thread Roelof Wobben
> Subject: Re: [Tutor] FW: find() problem > From: evert@gmail.com > Date: Tue, 24 Aug 2010 17:03:07 +0200 > CC: tutor@python.org > To: rwob...@hotmail.com > > > > > def find(strng, ch, start, step=1): > > > > index = start > > > The prob

Re: [Tutor] FW: find() problem

2010-08-24 Thread Evert Rol
> > > def find(strng, ch, start, step=1): > > > index = start > > The problem lies here, if you do a print on index, it never gets past > > the first index of the number, so > > your while loop below goes into an infinite loop. > > > > For example: > > find('starfruit','t',0) <- First time wil