A simpler one-liner:
def most_common(lst):
return max(set(lst), key=lst.count)
More Related Contents:
- How to iterate through two lists in parallel?
- Transpose/Unzip Function (inverse of zip)?
- From list of integers, get number closest to a given value
- sort() and reverse() functions do not work
- How to split elements of a list?
- Loop “Forgets” to Remove Some Items [duplicate]
- How can I verify if one list is a subset of another?
- List vs tuple, when to use each? [duplicate]
- Deleting multiple elements from a list
- Iterating through list of list in Python
- Function changes list values and not variable values in Python [duplicate]
- Extending list returns None [duplicate]
- Interleaving Lists in Python [duplicate]
- Does a slicing operation give me a deep or shallow copy?
- Confused about __str__ on list in Python [duplicate]
- join two lists of dictionaries on a single key
- Python – How to sort a list of lists by the fourth element in each list? [duplicate]
- Confusing […] List in Python: What is it?
- How to delete an item in a list if it exists?
- Flattening a list recursively [duplicate]
- remove None value from a list without removing the 0 value
- Python: Remove Duplicate Items from Nested list
- Changing one dict changes all dicts in a list of dicts [duplicate]
- Python string.join(list) on object array rather than string array
- How to sort multidimensional array by column?
- sum each value in a list of tuples
- Python and SQLite: insert into table
- Creating a list in Python with multiple copies of a given object in a single line
- How to create a number of empty nested lists in python [duplicate]
- How can I turn a flat list into a 2D array in python?