Clustering the keys of a dict according to its values
alex23
wuwei23 at gmail.com
Fri Nov 14 08:42:38 EST 2008
More information about the Python-list mailing list
Fri Nov 14 08:42:38 EST 2008
- Previous message (by thread): Clustering the keys of a dict according to its values
- Next message (by thread): Clustering the keys of a dict according to its values
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Nov 14, 11:24 pm, bearophileH... at lycos.com wrote: > Alternative version: > > def cluster(data): > d = defaultdict(list) > pairs = enumerate(data) if isinstance(data, list) else > data.iteritems() > for k, v in pairs: > d[v].append(k) > return d > > Bye, > bearophile Very nice, +1.
- Previous message (by thread): Clustering the keys of a dict according to its values
- Next message (by thread): Clustering the keys of a dict according to its values
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list