<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
On 31.10.2017 8:37, <a class="moz-txt-link-abbreviated"
href="mailto:python-ideas-request@python.org">python-ideas-request@python.org</a>
wrote:<br>
<blockquote type="cite"
cite="mid:mailman.1135.1509428278.1486.python-ideas@python.org">
<pre wrap=""><div class="moz-txt-sig">On Tue, Oct 31, 2017 at 3:50 PM, Ivan Pozdeev via Python-ideas
<a class="moz-txt-link-rfc2396E" href="mailto:python-ideas@python.org" moz-do-not-send="true"><python-ideas@python.org></a> wrote:
</div></pre>
<blockquote type="cite" style="color: #000000;">
<pre wrap="">On 30.10.2017 17:32, Guido van Rossum wrote:
</pre>
<blockquote type="cite" style="color: #000000;">
<pre wrap="">This is a key example of a case where code speaks. Can you write an
implementation of how you would want single() to work in Python code?
On Mon, Oct 30, 2017 at 2:49 AM, Ivan Pozdeev via Python-ideas
<<a class="moz-txt-link-abbreviated" href="mailto:python-ideas@python.org" moz-do-not-send="true">python-ideas@python.org</a> <a class="moz-txt-link-rfc2396E" href="mailto:python-ideas@python.org" moz-do-not-send="true"><mailto:python-ideas@python.org></a>> wrote:
The initial post on the above link summarizes the suggested
implementation pretty well.
</pre>
</blockquote>
<pre wrap="">|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')||| |
||
</pre>
</blockquote>
<pre wrap="">raise WhitespaceDamagedException from None
ChrisA</pre>
</blockquote>
<br>
Thunderbird jerked on me big time. It never did anything like this
before! Switched off Digest mode, individual messages aren't so
complicated.<br>
<br>
def single(i):<br>
try:<br>
v =i.next()<br>
except StopIteration:<br>
raise ValueError('No items')<br>
try:<br>
i.next()<br>
except StopIteration:<br>
return v<br>
else:<br>
raise ValueError('More than one item')<br>
<br>
print single(name for name in('bob','fred') if name=='bob')<br>
<br>
--
<pre class="moz-signature" cols="72">Regards,
Ivan</pre>
</body>
</html>