analogue argmax for list of multidimensional arrays (PYTHON) -
is there efficient way of finding element occurs in list given element array of length 2?
example:
l = [(1,0),(1,0),(1,1),(0,0),(1,0)]
i return: (1,0) appears often.
appears simple can't find way this.
you use collections.counter
>>> import collections >>> l = [(1,0),(1,0),(1,1),(0,0),(1,0)] >>> c = collections.counter(l) >>> c.most_common(1) [((1, 0), 3)]
otherwise can use max
lambda key
argument
>>> max(l, key = lambda i: l.count(i)) (1, 0)
Comments
Post a Comment