Re: iterator wrapper

2006-08-12 Thread alf
Simon Forman wrote: > Yes, you've got it, the xrange() version will not allocate a huge list. > > It's not part of your main question, and I understand that there may be > reasons why you can't, but consider upgrading to 2.4 (or very soon now > 2.5...) upgrade to 2.4 is on the roadmap and will t

Re: iterator wrapper

2006-08-12 Thread Simon Forman
alf wrote: > Simon Forman wrote: > >> > >>>|>> I = ([n] for n in i) > >> > >>This is nice but I am iterating thru hude objects (like MBs) so you know ... > >> > > > > No, I don't know... :-) > > potentially my source lists are huge - so wanted to avoid unnecessary > memory allocation > > > > My fr

Re: iterator wrapper

2006-08-12 Thread alf
Paul Rubin wrote: > alf <[EMAIL PROTECTED]> writes: > >>>|>> I = ([n] for n in i) >> >>This is nice but I am iterating thru hude objects (like MBs) so you know ... > > > I don't understand the objection-- the above is entirely correct and > produces the same iterator you'd get from > > def

Re: iterator wrapper

2006-08-12 Thread alf
Simon Forman wrote: >> >>>|>> I = ([n] for n in i) >> >>This is nice but I am iterating thru hude objects (like MBs) so you know ... >> > > No, I don't know... :-) potentially my source lists are huge - so wanted to avoid unnecessary memory allocation > My friend, I think you've misunderstood

Re: iterator wrapper

2006-08-11 Thread Simon Forman
alf wrote: > Simon Forman wrote: > > >class LW(object): # ListWrapper > >>... def __init__(self, i): > >>... self.theiter = i > >>... def next(self): > >>... return [self.theiter.next()] > > > I hoped one lamda would take care of it but looks like it is a simplest > choi

Re: iterator wrapper

2006-08-11 Thread Paul Rubin
alf <[EMAIL PROTECTED]> writes: > > |>> I = ([n] for n in i) > > This is nice but I am iterating thru hude objects (like MBs) so you know ... I don't understand the objection-- the above is entirely correct and produces the same iterator you'd get from def wrap(i): for x in i:

Re: iterator wrapper

2006-08-11 Thread alf
Simon Forman wrote: >class LW(object): # ListWrapper >>... def __init__(self, i): >>... self.theiter = i >>... def next(self): >>... return [self.theiter.next()] I hoped one lamda would take care of it but looks like it is a simplest choice. > |>> I = ([n] for n in

Re: iterator wrapper

2006-08-11 Thread Simon Forman
John Machin wrote: > alf wrote: > > Hi, > > > > I have a following task: let's say I do have an iterator returning the > > some objects: > > > > >>i= > > >>i.next() > > 1 > > >>i.next() > > 'abgfdgdfg' > > >>i.next() > > > > > > > > For some reason I need to wrap thos objects with a list. I th

Re: iterator wrapper

2006-08-11 Thread John Machin
alf wrote: > Hi, > > I have a following task: let's say I do have an iterator returning the > some objects: > > >>i= > >>i.next() > 1 > >>i.next() > 'abgfdgdfg' > >>i.next() > > > > For some reason I need to wrap thos objects with a list. I thought I > could have a smart lamda or simple funct

iterator wrapper

2006-08-11 Thread alf
Hi, I have a following task: let's say I do have an iterator returning the some objects: >>i= >>i.next() 1 >>i.next() 'abgfdgdfg' >>i.next() For some reason I need to wrap thos objects with a list. I thought I could have a smart lamda or simple function class yielding following result: