:) ok grazie<br><br><br><div class="gmail_quote">Il giorno 12 febbraio 2011 10:16, Enrico Franchi <span dir="ltr"><<a href="mailto:enrico.franchi@gmail.com">enrico.franchi@gmail.com</a>></span> ha scritto:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><div class="h5">Nicola Ferrari wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
ho un dizionario di n elementi.. per prendere il valore massimo faccio<br>
max(dizionario.values()).. esiste un metodo che dato un valore mi<br>
recupera la chiave di questo valore?<br>
</blockquote>
<br></div></div>
Non un metodo efficiente. Un dizionario e' fatto per recuperare efficientemente il valore data una chiave, non viceversa.<br>
Quello che io farei e' ottenerlo automaticamente durante la scansione comunque lineare del dizionario che fai per values.<br>
<br>
In [1]: d =dict(a=10, b=1000, c=10000)<br>
<br>
In [2]: max?<br>
Type:           builtin_function_or_method<br>
Base Class:     <type 'builtin_function_or_method'><br>
String Form:    <built-in function max><br>
Namespace:      Python builtin<br>
Docstring:<br>
    max(iterable[, key=func]) -> value<br>
    max(a, b, c, ...[, key=func]) -> value<br>
<br>
    With a single iterable argument, return its largest item.<br>
    With two or more arguments, return the largest argument.<br>
<br>
<osserva il parametro key><br>
<br>
<br>
In [3]: import operator as op<br>
In [4]: max(d.iteritems(), key=op.itemgetter(1))<br>
Out[4]: ('c', 10000)<br>
<br>
Eccoti li il massimo secondo il valore, con bello e pronto anche la sua chiave.<br><font color="#888888">
<br>
-- <br>
.<br>
..: -enrico-<br>
<br>
_______________________________________________<br>
Python mailing list<br>
<a href="mailto:Python@lists.python.it" target="_blank">Python@lists.python.it</a><br>
<a href="http://lists.python.it/mailman/listinfo/python" target="_blank">http://lists.python.it/mailman/listinfo/python</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Nicola Ferrari<br>website: <a href="http://www.nicolaferrari.name">http://www.nicolaferrari.name</a><br><br>skype: nick.ferro<br><br>