-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 27/09/2013 13:26, Piergiuliano Bossi wrote:
Perche' non usare invece una funzione libera che accetta un oggetto del tipo usato nella collezione? Se ti piace costruire a partire da blocchi principali, allora per prima cosa ci serve una funziona che restituisce il valore massimo in una sequenza e l'indice all'interno della sequenza che corrisponde a questo massimo. def max_idx(seq): # NOTE: this implementation do not support generators; # assume seq is not empty max = seq[0] max_idx = 0 for idx, value in enumerate(seq, start=1): if value > max: max = value max_idx = idx # Return the index of the first occurrence of the max value return max, max_idx def max_value(seq, functor): # NOTE: do not support generators (really!) max, max_idx = max_idx(map(functor, seq)) return seq[max_idx] Non mi pronuncio sull'efficienza. Ciao Manlio -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Icedove - http://www.enigmail.net/ iEYEARECAAYFAlJFdM0ACgkQscQJ24LbaUSqJQCfe4w0D+hSSFtBjE/hweGKjYyS 8ZYAnAm+vQBvSdPHTsdjuTe3JhJcjNKH =28aH -----END PGP SIGNATURE----- _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python