I understand
a = max(set(lst), key=lst.count)
will derive most common element in a list
but how do you derive most common element in a list of list without using helper function?
For example
lst = [['1','2','3','4'],['1','1','1','1'],['1','2','3','4']]
The output should equal 1.
When I try a = max(set(lst), key=lst.count)
it writes builtins.TypeError: unhashable type: 'list'
Can anyone please help me?
There are many ways, but I wanted to let you know that there are some nice tools for that kind of things in the standard modules, e.g.
collections.Counter:Or, you could (kinda) employ your current solution for each of the sublists: