Re: How to stop iteration

2011-06-05 Thread Shashank Singh
You can modify your code to stop trying to split the 'remaining part' when the 'remaining part' is too small def strsplit(stri, spa): if len(stri) <= spa: final_result.append(stri) return s = stri[:spa] final_result.append(s) stri = stri[spa:] strsplit(stri,spa

Re: How to stop iteration

2011-06-05 Thread Nitin Pawar
check length of input string with if stri.len > 3 On Sun, Jun 5, 2011 at 8:35 PM, Ganapathy Subramanium < sganapathy.subraman...@gmail.com> wrote: > Hi All, > > I'm a new bie to programming and need some assistance in this code. > > I have a function which will split the given string into 3 chara

How to stop iteration

2011-06-05 Thread Ganapathy Subramanium
Hi All, I'm a new bie to programming and need some assistance in this code. I have a function which will split the given string into 3 characters each and I want to achieve this by recursion. I have written the following code, but I don't know how to stop the recursion when the length of the rem

Re: How to stop iteration with __iter__() ?

2008-08-20 Thread Steven D'Aprano
On Wed, 20 Aug 2008 06:16:17 -0700, MRAB wrote: > So it's defined behaviour that an exhausted iterable will always raise > StopIteration no matter how many times it's asked for the next value? Be careful -- an iterable is not the same as an iterator. Iterables are anything that you can iterate o

Re: How to stop iteration with __iter__() ?

2008-08-20 Thread Peter Otten
MRAB wrote: > So it's defined behaviour that an exhausted iterable will always raise > StopIteration no matter how many times it's asked for the next value? That is not enforced. However, quoting http://www.python.org/dev/peps/pep-0234/ """ Iterator implementations (in C or in Python) should gua

Re: How to stop iteration with __iter__() ?

2008-08-20 Thread MRAB
On Aug 20, 11:27 am, John Machin <[EMAIL PROTECTED]> wrote: > On Aug 20, 7:56 pm, MRAB <[EMAIL PROTECTED]> wrote: > > > > > On Aug 20, 12:11 am, John Machin <[EMAIL PROTECTED]> wrote: > > > > or, perhaps, for completeness/paranoia/whatever: > > > > it = iter(iterable) > > > try: > > >    headings =

Re: How to stop iteration with __iter__() ?

2008-08-20 Thread John Machin
On Aug 20, 7:56 pm, MRAB <[EMAIL PROTECTED]> wrote: > On Aug 20, 12:11 am, John Machin <[EMAIL PROTECTED]> wrote: > > > or, perhaps, for completeness/paranoia/whatever: > > > it = iter(iterable) > > try: > >    headings = it.next() # < 2.5 > > except StopIteration: > >    # code to handle empty >

Re: How to stop iteration with __iter__() ?

2008-08-20 Thread MRAB
On Aug 20, 12:11 am, John Machin <[EMAIL PROTECTED]> wrote: > On Aug 20, 5:06 am, Terry Reedy <[EMAIL PROTECTED]> wrote: > > > In your case, the standard Python idiom, as Jon said, is > > > it = iter(iterable) > > next(it) # 2.6, 3.0 > > for for item in iterable: > >    f(item) > > or, perhaps, for

Re: How to stop iteration with __iter__() ?

2008-08-19 Thread John Machin
On Aug 20, 5:06 am, Terry Reedy <[EMAIL PROTECTED]> wrote: > In your case, the standard Python idiom, as Jon said, is > > it = iter(iterable) > next(it) # 2.6, 3.0 > for for item in iterable: >f(item) or, perhaps, for completeness/paranoia/whatever: it = iter(iterable) try: headings = it.n

Re: How to stop iteration with __iter__() ?

2008-08-19 Thread Terry Reedy
ssecorp wrote: I want a parse a file of the format: movieId customerid, grade, date customerid, grade, date customerid, grade, date etc. so I could do with open file as reviews and then for line in reviews. but first I want to take out the movie id so I use an iterator. then i want to iterat

Re: How to stop iteration with __iter__() ?

2008-08-19 Thread Leo Jay
On Tue, Aug 19, 2008 at 7:39 PM, ssecorp <[EMAIL PROTECTED]> wrote: > I want a parse a file of the format: > movieId > customerid, grade, date > customerid, grade, date > customerid, grade, date > etc. > > so I could do with open file as reviews and then for line in reviews. > > but first I want to

Re: How to stop iteration with __iter__() ?

2008-08-19 Thread Jon Clements
On Aug 19, 12:39 pm, ssecorp <[EMAIL PROTECTED]> wrote: > I want a parse a file of the format: > movieId > customerid, grade, date > customerid, grade, date > customerid, grade, date > etc. > > so I could do with open file as reviews and then for line in reviews. > > but first I want to take out th

Re: How to stop iteration with __iter__() ?

2008-08-19 Thread Jeff
On Aug 19, 7:39 am, ssecorp <[EMAIL PROTECTED]> wrote: > I want a parse a file of the format: > movieId > customerid, grade, date > customerid, grade, date > customerid, grade, date > etc. > > so I could do with open file as reviews and then for line in reviews. > > but first I want to take out the

How to stop iteration with __iter__() ?

2008-08-19 Thread ssecorp
I want a parse a file of the format: movieId customerid, grade, date customerid, grade, date customerid, grade, date etc. so I could do with open file as reviews and then for line in reviews. but first I want to take out the movie id so I use an iterator. then i want to iterate through all the r