How to count the occurrences of specific item in a list with Python

2 Answers

0 votes
lst = ["python", "java", "888", "9", "c", "python", "109", "c++", "c", "python"]

result = lst.count("python")

print(result)



'''
run:

3

'''

 



answered Nov 23, 2018 by avibootz
edited Feb 18, 2024 by avibootz
0 votes
lst = ["python", "php", "php", "c++", "php", "c"]
 
s = "php"
count = 0
 
for item in lst:
    if item == s:
        count += 1
 
print(count)
 
 
 
'''
run:
 
3
 
'''

 



answered Nov 23, 2018 by avibootz
edited Feb 18, 2024 by avibootz
...