Keeping track of the N largest values
Paul Rubin
no.email at nospam.invalid
Sat Dec 25 14:41:58 EST 2010
More information about the Python-list mailing list
Sat Dec 25 14:41:58 EST 2010
- Previous message (by thread): Keeping track of the N largest values
- Next message (by thread): Keeping track of the N largest values
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Roy Smith <roy at panix.com> writes: >> from heapq import nlargest >> top = nlargest(K, input()) > In addition to finding the K largest values, I *also* need to do some > other processing on all the values .... The problem with nlargest() > is that it doesn't give me a hook to do that. def processed_input(): for x in input(): process(x) yield x top = nlargest(K, processed_input()) You could also write that more consisely with genexps but it's a bit clumsy.
- Previous message (by thread): Keeping track of the N largest values
- Next message (by thread): Keeping track of the N largest values
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list