Re: getting n items at a time from a generator

2008-01-10 Thread Shane Geiger
Paul Rubin wrote: > Tim Roberts <[EMAIL PROTECTED]> writes: > >> I have to say that I have found this to be a surprisingly common need as >> well. Would this be an appropriate construct to add to itertools? >> > > I'm in favor. > I am ecs

Re: getting n items at a time from a generator

2008-01-10 Thread Paul Rubin
Tim Roberts <[EMAIL PROTECTED]> writes: > I have to say that I have found this to be a surprisingly common need as > well. Would this be an appropriate construct to add to itertools? I'm in favor. -- http://mail.python.org/mailman/listinfo/python-list

Re: getting n items at a time from a generator

2007-12-31 Thread NickC
On Dec 27 2007, 11:31 pm, Kugutsumen <[EMAIL PROTECTED]> wrote: > On Dec 27, 7:24 pm, Terry Jones <[EMAIL PROTECTED]> wrote: > > > > > > "Kugutsumen" == Kugutsumen <[EMAIL PROTECTED]> writes: > > > Kugutsumen> On Dec 27, 7:07 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > > > >> On Dec 27, 11:34

Re: getting n items at a time from a generator

2007-12-29 Thread Raymond Hettinger
> > Also consider this solution from O'Reilly's Python Cookbook (2nd Ed.) p705 > > >     def chop(iterable, length=2): > >         return izip(*(iter(iterable),) * length) > > However, chop ignores the remainder of the data in the example. There is a recipe in the itertools docs which handles the

Re: getting n items at a time from a generator

2007-12-29 Thread Raymond Hettinger
> >     def chop(iterable, length=2): > >         return izip(*(iter(iterable),) * length) > > Is this *always* guaranteed by the language to work? Yes! Users requested this guarantee, and I agreed. The docs now explicitly guarantee this behavior. Raymond -- http://mail.python.org/mailman/lis

Re: getting n items at a time from a generator

2007-12-29 Thread Terry Jones
Hi Igor > "Igor" == Igor V Rafienko <[EMAIL PROTECTED]> writes: >> Also consider this solution from O'Reilly's Python Cookbook (2nd Ed.) >> p705 >> >> def chop(iterable, length=2): >> return izip(*(iter(iterable),) * length) Igor> Is this *always* guaranteed by the language to work? Should

Re: getting n items at a time from a generator

2007-12-29 Thread Igor V. Rafienko
[ Terry Jones ] [ ... ] > Also consider this solution from O'Reilly's Python Cookbook (2nd Ed.) p705 > > def chop(iterable, length=2): > return izip(*(iter(iterable),) * length) Is this *always* guaranteed by the language to work? Should the iterator returned by izip() change the i

Re: getting n items at a time from a generator

2007-12-29 Thread Neil Cerutti
On Dec 29, 2007 2:18 AM, Tim Roberts <[EMAIL PROTECTED]> wrote: > Kugutsumen <[EMAIL PROTECTED]> wrote: > > > >I am relatively new the python language and I am afraid to be missing > >some clever construct or built-in way equivalent to my 'chunk' > >generator below. > > I have to say that I have f

Re: getting n items at a time from a generator

2007-12-28 Thread Tim Roberts
Kugutsumen <[EMAIL PROTECTED]> wrote: > >I am relatively new the python language and I am afraid to be missing >some clever construct or built-in way equivalent to my 'chunk' >generator below. I have to say that I have found this to be a surprisingly common need as well. Would this be an appropri

Re: getting n items at a time from a generator

2007-12-27 Thread Shane Geiger
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496958 from itertools import * def group(lst, n): """group([0,3,4,10,2,3], 2) => iterator Group an iterable into an n-tuples iterable. Incomplete tuples are padded with Nones e.g. >>> list(group(range(10), 3)) [(0, 1,

Re: getting n items at a time from a generator

2007-12-27 Thread Kugutsumen
On Dec 27, 7:24 pm, Terry Jones <[EMAIL PROTECTED]> wrote: > > "Kugutsumen" == Kugutsumen  <[EMAIL PROTECTED]> writes: > > Kugutsumen> On Dec 27, 7:07 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > > >> On Dec 27, 11:34 am, Kugutsumen <[EMAIL PROTECTED]> wrote: > > >> > I am relatively new the py

Re: getting n items at a time from a generator

2007-12-27 Thread Kugutsumen
On Dec 27, 7:24 pm, Terry Jones <[EMAIL PROTECTED]> wrote: > > "Kugutsumen" == Kugutsumen  <[EMAIL PROTECTED]> writes: > > Kugutsumen> On Dec 27, 7:07 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > > >> On Dec 27, 11:34 am, Kugutsumen <[EMAIL PROTECTED]> wrote: > > >> > I am relatively new the py

Re: getting n items at a time from a generator

2007-12-27 Thread Terry Jones
> "Kugutsumen" == Kugutsumen <[EMAIL PROTECTED]> writes: Kugutsumen> On Dec 27, 7:07 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: >> On Dec 27, 11:34 am, Kugutsumen <[EMAIL PROTECTED]> wrote: >> >> > I am relatively new the python language and I am afraid to be missing >> > some clever construc

Re: getting n items at a time from a generator

2007-12-27 Thread Steven D'Aprano
On Thu, 27 Dec 2007 03:34:57 -0800, Kugutsumen wrote: > I am relatively new the python language and I am afraid to be missing > some clever construct or built-in way equivalent to my 'chunk' generator > below. > > def chunk(size, items): > """generate N items from a generator.""" [snip code

Re: getting n items at a time from a generator

2007-12-27 Thread Kugutsumen
On Dec 27, 7:07 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > On Dec 27, 11:34 am, Kugutsumen <[EMAIL PROTECTED]> wrote: > > > > > I am relatively new the python language and I am afraid to be missing > > some clever construct or built-in way equivalent to my 'chunk' > > generator below. > > > def c

Re: getting n items at a time from a generator

2007-12-27 Thread Paul Hankin
On Dec 27, 11:34 am, Kugutsumen <[EMAIL PROTECTED]> wrote: > I am relatively new the python language and I am afraid to be missing > some clever construct or built-in way equivalent to my 'chunk' > generator below. > > def chunk(size, items): >     """generate N items from a generator.""" >     chu

getting n items at a time from a generator

2007-12-27 Thread Kugutsumen
I am relatively new the python language and I am afraid to be missing some clever construct or built-in way equivalent to my 'chunk' generator below. def chunk(size, items): """generate N items from a generator.""" chunk = [] count = 0 while True: try: item = it