2013/9/27 Marco Beri <[email protected]>
> 2013/9/27 Valerio Maggio <[email protected]>
>
>> def _max_value(self):
>> return max(self._values, key=lambda v: v.func())
>>
>
> Eh, torna il valore calcolato e non quello originale...
>
In realtà torna l'originale:
In [27]: class C():
def __init__(self, val):
self.val = val
def func(self):
return self.val
....:
In [28]: values = [C(x) for x in range(10)]
In [29]: value = max(values, key=lambda v: v.func())
In [30]: value is values[-1]
Out[30]: True
In [31]: result = max(value.func() for value in values)
In [32]: result is values[-1].func()
Out[32]: True
--
Nadir
_______________________________________________
Python mailing list
[email protected]
http://lists.python.it/mailman/listinfo/python