On Wed, 04 May 2005 20:33:31 +, Leif K-Brooks wrote:
> With the EmptyGeneratorDetector class as you defined it, lists will fail:
>
> >>> EmptyGeneratorDetector([])
> Traceback (most recent call last):
>File "", line 1, in ?
>File "", line 15, in __init__
> AttributeError: 'list' objec
Jeremy Bowers wrote:
> On Wed, 04 May 2005 13:45:00 +, Leif K-Brooks wrote:
>
>
>>Jeremy Bowers wrote:
>>
>>>def __init__(self, generator):
>>>self.generator = generator
>>
>>You'll want to use iter(generator) there in order to handle reiterables.
>
>
> Can you expand that expla
On Wed, 04 May 2005 13:45:00 +, Leif K-Brooks wrote:
> Jeremy Bowers wrote:
>> def __init__(self, generator):
>> self.generator = generator
>
> You'll want to use iter(generator) there in order to handle reiterables.
Can you expand that explanation a bit? I'm not certain what you
Jeremy Bowers wrote:
> def __init__(self, generator):
> self.generator = generator
You'll want to use iter(generator) there in order to handle reiterables.
--
http://mail.python.org/mailman/listinfo/python-list
Andrea Griffini:
> Are you sure this is going to do the right thing ?
Argh! I missed these two lines from the documentation:
"""Note, once tee() has made a split, the original iterable should not
be used anywhere else; otherwise, the iterable could get advanced
without the tee objects being info
On 2 May 2005 21:49:33 -0700, "Michele Simionato"
<[EMAIL PROTECTED]> wrote:
>Starting from Python 2.4 we have tee in the itertools
>module, so you can define the following:
>
>from itertools import tee
>
>def is_empty(it):
>it_copy = tee(it)[1]
>try:
>it_copy.next()
>except St
"Brian Roberts" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm using using generators and iterators more and more intead of
> passing lists around, and prefer them. However, I'm not clear on the
> best way to detect an empty generator (one that will return no items)
> when som
Starting from Python 2.4 we have tee in the itertools
module, so you can define the following:
from itertools import tee
def is_empty(it):
it_copy = tee(it)[1]
try:
it_copy.next()
except StopIteration:
return True
else:
return False
It works with generic i
On 2 May 2005 16:14:57 -0700, [EMAIL PROTECTED] (Brian Roberts) wrote:
>I'm using using generators and iterators more and more intead of
>passing lists around, and prefer them. However, I'm not clear on the
>best way to detect an empty generator (one that will return no items)
>when some sort of
On Mon, 02 May 2005 16:14:57 -0700, Brian Roberts wrote:
> Q1: Is there a better or alternate way to handle this? Q2: Is there a way
> that handles both lists and generators, so I don't have to worry about
> which one I've got?
Are you in control of your generators? You could put a method on them
In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] (Brian Roberts) wrote:
> I'm using using generators and iterators more and more intead of
> passing lists around, and prefer them. However, I'm not clear on the
> best way to detect an empty generator (one that will return no items)
> when some s
Brian Roberts wrote:
> I'm using using generators and iterators more and more intead of
> passing lists around, and prefer them. However, I'm not clear on the
> best way to detect an empty generator (one that will return no items)
> when some sort of special case handling is required.
>
Usually
I'm using using generators and iterators more and more intead of
passing lists around, and prefer them. However, I'm not clear on the
best way to detect an empty generator (one that will return no items)
when some sort of special case handling is required.
Typical code for handling an empty list:
13 matches
Mail list logo