<div dir="ltr">2013/9/27 Marco Beri <span dir="ltr"><<a href="mailto:marcoberi@gmail.com" target="_blank">marcoberi@gmail.com</a>></span><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">2013/9/27 Valerio Maggio <span dir="ltr"><<a href="mailto:valerio.maggio@gmail.com" target="_blank">valerio.maggio@gmail.com</a>></span><br><div class="gmail_extra"><div class="gmail_quote"><div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">def _max_value(self):</span><br><div class="gmail_extra"><div class="gmail_quote"><div>
<div style="font-family:arial,sans-serif;font-size:13px"> return max(self._values, key=lambda v: v.func())</div></div></div></div></div></blockquote><div><br></div></div><div>Eh, torna il valore calcolato e non quello originale...</div>
</div></div></div></blockquote><div><br></div><div>In realtà torna l'originale:</div><div><br></div><div><div><font face="courier new, monospace">In [27]: class C(): </font></div><div><font face="courier new, monospace"> def __init__(self, val):</font></div>
<div><font face="courier new, monospace"> self.val = val</font></div><div><font face="courier new, monospace"> def func(self):</font></div><div><font face="courier new, monospace"> return self.val</font></div>
<div><font face="courier new, monospace"> ....: </font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">In [28]: values = [C(x) for x in range(10)]</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">In [29]: </font><span style="font-family:'courier new',monospace">value</span><font face="courier new, monospace"> = max(</font><span style="font-family:'courier new',monospace">value</span><span style="font-family:'courier new',monospace">s, key=lambda v: v.func())</span></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">In [30]: </font><span style="font-family:'courier new',monospace">value</span><font face="courier new, monospace"> is </font><span style="font-family:'courier new',monospace">value</span><span style="font-family:'courier new',monospace">s[-1]</span></div>
<div><font face="courier new, monospace">Out[30]: True</font></div></div></div><div class="gmail_extra"><font face="courier new, monospace"><br></font></div><div class="gmail_extra"><font face="courier new, monospace">In [31]: result = max(value.func() for value in values)</font></div>
<div class="gmail_extra"><font face="courier new, monospace"><br></font></div><div class="gmail_extra"><font face="courier new, monospace">In [32]: result is values[-1].func()</font></div><div class="gmail_extra"><font face="courier new, monospace">Out[32]: True</font></div>
<div><br></div><div class="gmail_extra"><br></div>-- <br><div dir="ltr">Nadir<br></div>
</div></div>