r/pythonhelp • • Oct 15 '22

Getting count of string

Get Counts of (A, An, The) in a paragraph. The article should be given as input while running the script.

0 Upvotes

5 comments sorted by

1

u/CraigAT Oct 15 '22

Sounds like homework. What have you got so far?

1

u/[deleted] Oct 15 '22

I came up with many solution nothing is working I can do it for a one like only 'a' or 'an but three not working

2

u/CraigAT Oct 15 '22

Are there any errors when you run your code?

There are several ways you could do this. My initial thought is to split the sentence into a list of words and then check if each word is in the list of words you are looking for, then add to a counter (a dictionary may work well here as you have multiple counters). You may want to make use of lower() to make any comparisons case insensitive.

1

u/AmongstYou666 Oct 16 '22
a = "the rain in spain".split(' ')
count_these = "a an the".split(' ')
for i in count_these:
    print(i, a.count(i)

1

u/[deleted] Oct 16 '22

Thank you so much 🥰