<div dir="ltr"><div><div>sure it works if `eggs` has a `__iadd__` method. why shouldn’t it use the outer local?<br><br></div>but that’s irrelevant. as i said: what i did is closest thing. yet in some other respects, if/else is closer, as there is no real alternative to a switch statement in python.<br>
<br></div><div>my only point is that apart from being cleaner, a switch block also behaves differently than a if/else chain, and performs better.<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-04-26 15:27 GMT+02:00 Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Sat, Apr 26, 2014 at 11:03 PM, Philipp A. <<a href="mailto:flying-sheep@web.de">flying-sheep@web.de</a>> wrote:<br>
> in python, the most similar thing is something like this:<br>
><br>
</div><div class="">> 'key1': lambda: eggs += lay_eggs(), #branch 1<br>
<br>
</div>Except that lambda doesn't create a code block, it creates a nested<br>
function. This example won't work, and nor will anything else that<br>
needs to mutate locals; you'd have to declare an out-of-line function<br>
(as with branch_2_3) to be able to assign to 'nonlocal eggs'.<br>
<br>
ChrisA<br>
<div class="HOEnZb"><div class="h5">_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</div></div></blockquote></div><br></div>