# [Python-ideas] Python-ideas Digest, Vol 131, Issue 106

Koos Zevenhoven k7hoven at gmail.com
Tue Oct 31 04:54:41 EDT 2017

```On Tue, Oct 31, 2017 at 10:01 AM, Chris Angelico <rosuav at gmail.com> wrote:

> On Tue, Oct 31, 2017 at 6:46 PM, Steven D'Aprano <steve at 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')

People need to learn about how to make a 1-tuple quite early on anyway, and
omitting the parentheses doesn't really help there, AFAICT. Then again, the
idiom looks even better when doing

a, b = find_complex_roots(polynomial_of_second_order)

Except of course that I couldn't really come up with a good example of
something that is expected to find exactly two values from a larger
collection, and the students are already coming into the lecture hall.

Or should it be

(a, b,) = find_complex_roots(polynomial_of_second_order)

?

––Koos

--
+ Koos Zevenhoven + http://twitter.com/k7hoven +
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171031/17d3b74d/attachment.html>
```