0
Q:

python most frequently occuring string in a list

test = [1, 2, 3, 4, 2, 2, 3, 1, 4, 4, 4] 
print(max(set(test), key = test.count)) 
2
# Program to return the most frequent element in a list 
def most_frequent(List): 
    return max(set(List), key = List.count) 

# Example usage:
List = ['fish', 42, 'apple', 'fish', 'fish', 'cow', 23] 
print(most_frequent(List))
--> fish
1
from collections import Counter

a = [1936, 2401, 2916, 4761, 9216, 9216, 9604, 9801] 

c = Counter(a)

print(c.most_common(1)) # the one most common element... 2 would mean the 2 most common
[(9216, 2)] # a set containing the element, and it's count in 'a'
2

New to Communities?

Join the community