Answers for "count function python"

3

count similar values in list python

MyList = ["a", "b", "a", "c", "c", "a", "c"]

return my_dict = {i:MyList.count(i) for i in MyList}
# returns :
{'a': 3, 'c': 3, 'b': 1}
 # OR
from collections import Counter
return my_dict = dict(Counter(MyList))
# returns :   
{'a': 3, 'c': 3, 'b': 1}
# the both returns the same so it's up to you to choose the one you prefere ;)
Posted by: Guest on October-10-2020
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
4

count in python

it counts the number of elements in the list or in the string(words)
Posted by: Guest on June-06-2020
0

python count

points = [1, 4, 2, 9, 7, 8, 9, 3, 1]
x = points.count(9)
#prints how many times 9 occured in the list
Posted by: Guest on July-12-2021
-2

what is the use of count function in python

count = 0 
while count < 10 :
  print("Hello")
  count += 1
Posted by: Guest on March-02-2021

Python Answers by Framework

Browse Popular Code Answers by Language