#NEWLINE# def mostCommon( L ) : #NEWLINE# #INDENT# '\n        #   http://stackoverflow.com/questions/1518522/python-most-common-element-in-a-list\n        \n        >>> mostCommon([1, 2, 2, 3])\n        2\n        >>> mostCommon([1, 2, 3])\n        1\n        >>> mostCommon([-1, 2, 3])\n        -1\n        >>> mostCommon([-1, -2, -3])\n        -1\n        >>> mostCommon([-1, -2, -3, -1])\n        -1\n        >>> mostCommon([-1, -1, -2, -2])\n        -1\n        >>> mostCommon([0, 0.125, 0.275, 1])\n        0\n        >>> mostCommon([0, 0.1, 0.4, 0.4])\n        0.4\n    ' #NEWLINE# SL = sorted ( ( ( x , i ) for ( i , x ) in enumerate ( L ) ) ) #NEWLINE# groups = itertools . groupby ( SL , key = operator . itemgetter ( 0 ) ) #NEWLINE# def _auxfun( g ) : #NEWLINE# #INDENT# ( item , iterable ) = g #NEWLINE# count = 0 #NEWLINE# min_index = len ( L ) #NEWLINE# for ( _ , where ) in iterable : #NEWLINE# #INDENT# count += 1 #NEWLINE# min_index = min ( min_index , where ) #NEWLINE# #UNINDENT# return ( count , ( - min_index ) ) #NEWLINE# #UNINDENT# return max ( groups , key = _auxfun ) [ 0 ]