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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -