Answers for "count of each element of list in a word python"

0

How to take total count of words in the list python

#How to find total count of "BMW" cars from the list

car_list = ["BMW", "Audi", "BMW", "Mercedez", "BMW", "Ferrari"]

count = 0

for cars in car_list:
    if cars == "BMW":
        count = count + 1
print("Total BMW Cars in Garage are:-", count)
Posted by: Guest on March-30-2021
0

count number of each item in list python

word_counter = {}
book_title =  ['great', 'expectations','the', 'adventures', 'of', 'sherlock','holmes','the','great','gasby','hamlet','adventures','of','huckleberry','fin']

for word in book_title:
    if word not in word_counter:
        word_counter[word] = 1
    else:
        word_counter[word] += 1

print(word_counter)

# output - {'great': 2, 'expectations': 1, 'the': 2, 'adventures': 2, 'of': 2, 'sherlock': 1, 'holmes': 1, 'gasby': 1, 'hamlet': 1, 'huckleberry': 1, 'fin': 1}
Posted by: Guest on December-18-2021

Code answers related to "count of each element of list in a word python"

Python Answers by Framework

Browse Popular Code Answers by Language