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