On Tue, Oct 31, 2017 at 5:18 PM, Ivan Pozdeev via Python-ideas
<python-ideas@python.org> wrote:
>> raise WhitespaceDamagedException from None
>
>
> Thunderbird jerked on me big time. It never did anything like this before!
> Switched off Digest mode, individual messages aren't so complicated.
>
> def single(i):
>     try:
>         v =i.next()
>     except StopIteration:
>         raise ValueError('No items')
>     try:
>         i.next()
>     except StopIteration:
>         return v
>     else:
>         raise ValueError('More than one item')
>
> print single(name for name in('bob','fred') if name=='bob')
>

Thanks :)

One small change: If you use next(i) instead of i.next(), your code
should work on both Py2 and Py3. But other than that, I think it's
exactly the same as most people would expect of this function.

ChrisA
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to