Answers for "python frequency count of list"

1

list count frequency python

import collections
a = [1,1,1,1,2,2,2,2,3,3,4,5,5]
counter=collections.Counter(a)
print(counter)
# Counter({1: 4, 2: 4, 3: 2, 5: 2, 4: 1})
print(counter.values())
# [4, 4, 2, 1, 2]
print(counter.keys())
# [1, 2, 3, 4, 5]
print(counter.most_common(3))
# [(1, 4), (2, 4), (3, 2)]
Posted by: Guest on July-15-2020
0

python count the frequency of words in a list

from collections import Counter
list1=['apple','egg','apple','banana','egg','apple']
counts = Counter(list1)

print(counts)
# Counter({'apple': 3, 'egg': 2, 'banana': 1})
Posted by: Guest on February-25-2021
3

freq count in python

freq = {} 
    for item in my_list: 
        if (item in freq): 
            freq[item] += 1
        else: 
            freq[item] = 1
Posted by: Guest on July-21-2020
2

find frequency of numbers in list python

from collections import Counter

def frequency_table(n):
    table = Counter(n)
    print('NumbertFrequency')
    for number in table.most_common() :
        print('{0}t{1}'.format(number[0], number[1]))
        
# src : Doing Math With Python
Posted by: Guest on December-29-2020

Code answers related to "python frequency count of list"

Python Answers by Framework

Browse Popular Code Answers by Language