Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,894 questions

51,825 answers

573 users

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
...