On 10/31/2017 09:54 AM, Koos Zevenhoven wrote:
On Tue, Oct 31, 2017 at 10:01 AM, Chris Angelico <ros...@gmail.com
<mailto:ros...@gmail.com>>wrote:
On Tue, Oct 31, 2017 at 6:46 PM, Steven D'Aprano
<st...@pearwood.info <mailto:st...@pearwood.info>> wrote:
> On Tue, Oct 31, 2017 at 06:02:34PM +1100, Chris Angelico wrote:
>> 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.
>
> Not me. As far as I can tell, that's semantically equivalent to:
>
> def single(i):
> result, = i
> return result
>
> apart from slightly different error messages.
I saw the original code as being like the itertools explanatory
functions - you wouldn't actually USE those functions, but they tell
you what's going on when you use the simpler, faster, more compact
form.
I wonder if that's more easily understood if you write it along these
line(s):
(the_bob,) = (name for name in ('bob','fred') if name=='bob')
There are (unfortunately) several ways to do it. I prefer one that
avoids a trailing comma:
[the_bob] = (name for name in ('bob','fred') if name=='bob')
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/