Mercurial > hg > nsaunier > traffic-intelligence
comparison python/utils.py @ 456:825e5d49325d
slight update
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 19 Feb 2014 16:30:45 -0500 |
| parents | abe0b2347d4c |
| children | 30b3455978d9 |
comparison
equal
deleted
inserted
replaced
| 455:abe0b2347d4c | 456:825e5d49325d |
|---|---|
| 271 ######################### | 271 ######################### |
| 272 # iterable section | 272 # iterable section |
| 273 ######################### | 273 ######################### |
| 274 | 274 |
| 275 def mostCommon(L): | 275 def mostCommon(L): |
| 276 '''Returns the most frequent element in a iterable''' | 276 '''Returns the most frequent element in a iterable |
| 277 | |
| 278 taken from http://stackoverflow.com/questions/1518522/python-most-common-element-in-a-list''' | |
| 277 from itertools import groupby | 279 from itertools import groupby |
| 278 from operator import itemgetter | 280 from operator import itemgetter |
| 279 # get an iterable of (item, iterable) pairs | 281 # get an iterable of (item, iterable) pairs |
| 280 SL = sorted((x, i) for i, x in enumerate(L)) | 282 SL = sorted((x, i) for i, x in enumerate(L)) |
| 281 # print 'SL:', SL | 283 # print 'SL:', SL |
