[Python-ideas] Add single() to itertools

Koos Zevenhoven k7hoven at gmail.com
Tue Oct 31 03:53:54 EDT 2017


>
>
> |defsingle(i): try: ||v =i.next() |||exceptStopIteration:||||raiseException('No
> values')|||try: ||i.next() ||exceptStopIteration: ||returnv||else:
> ||raiseException('Too many values')|
> ||printsingle(name forname in('bob','fred')ifname=='bob')||| |
>
>
​Now that looks seriously weird. Oh wait, I know, it must be a regular
expression! Perhaps mixed with Perl? To figure out what it does, we could
try compiling it and throwing input at it, or perhaps more simply by just
reverse engineering the implementation.

––Koos​
​​

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


More information about the Python-ideas mailing list