On Fri, 03 Dec 2010 10:15:58 -0800, Paul Rubin wrote:

> Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> writes:
>> def func(iterable):
>>     it = iter(iterable)
>>     failed = False
>>     try:
>>         x = next(it)
>>     except StopIteration:
>>         failed = True
>>     if failed:
>>         raise ValueError("can't process empty iterable")
>>     print(x)
> 
> Untested:
> 
>     from itertools import islice
> 
>     def func(iterable):
>        xs = list(islice(iter(iterable), 1))
>        if len(xs) == 0:
>           raise ValueError(...)
>        print xs[0]


If you're intention was to make me feel better about the version above 
that sets a flag, you succeeded admirably!

:)


-- 
Steven



-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to