Count specific vowels in a sentence

DonnellyOverflow

I've found a few instances of this but my question is slightly different.

I need to scan a sentence like

For letter in sentence
if letter == "a" or letter == "A": letterATotal = letterATotal + 1
elif letter == "e" or letter == "E": letterETotal = letterETotal + 1

etc all the way to U. But then I need to compare them all and print the line containing the most frequent so "the most frequent vowel is A occurring 5 times". Problem is I don't know how to display the actual letter. I can only display the number. Any ideas?

user2555451

Look at this:

>>> from collections import Counter
>>> mystr = "AaAaaEeEiOoouuu"
>>> a,b = Counter(c for c in mystr.lower() if c in "aeiou").most_common(1)[0]
>>> "the most frequent vowel is {} occurring {} times".format(a.upper(), b)
'the most frequent vowel is A occurring 5 times'
>>>

Here is a reference on collections.Counter.


Edit:

Here is a step-by-step demonstration of what's going on:

>>> from collections import Counter
>>> mystr = "AaAaaEeEiOoouuu"
>>> Counter(c for c in mystr.lower() if c in "aeiou")
Counter({'a': 5, 'o': 3, 'e': 3, 'u': 3, 'i': 1})
>>> # Get the top three most common
>>> Counter(c for c in mystr.lower() if c in "aeiou").most_common(3)
[('a', 5), ('o', 3), ('e', 3)]
>>> # Get the most common
>>> Counter(c for c in mystr.lower() if c in "aeiou").most_common(1)
[('a', 5)]
>>> Counter(c for c in mystr.lower() if c in "aeiou").most_common(1)[0]
('a', 5)
>>> a,b = Counter(c for c in mystr.lower() if c in "aeiou").most_common(1)[0]
>>> a
'a'
>>> b
5
>>>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Count a occurrence of a specific word in a sentence haskell

From Dev

JAVA: I have to write a program to read "sentences" from a file and and then count the number of words and vowels per sentence

From Dev

find the occurence of all vowels in a sentence

From Dev

Count vowels in a word

From Dev

How to separate sentence into array items, by a specific count of words

From Dev

Count the number of vowels in an array in PHP

From Dev

Printing the vowels and the vowel count in a string

From Dev

Count the number of vowels in an array in PHP

From Dev

Count the number of sentence

From Dev

Count Number of Sentence Ruby

From Dev

How can I check how many consonants and vowels there are in a sentence in Java?

From Dev

Counting specific words in a sentence

From Dev

Program to count evens odds vowels and consonants in a string

From Dev

C++ vector and string, count vowels

From Dev

Unable to count vowels using java multithreading

From Dev

How to specific letter spacing in a sentence

From Dev

Count the number of vowels and print them in a manner that string having more vowels come first

From Dev

Remove all vowels in a sentence except for those which occur in the beginning of the word in R

From Dev

Remove all vowels in a sentence except for those which occur in the beginning of the word in R

From Dev

In Python, how do I check the first two letters of each word in a sentence to see if they have vowels in them?

From Dev

How to count vowels in a String including which have accent marks?

From Dev

Count the vowels in a string including Y if its followed by a consonant

From Dev

is there a more efficient way to count how many vowels in a string?

From Dev

how to count the words in a sentence in mysql pdo

From Dev

At column, Count word in comma-separated sentence

From Dev

Python Palindrome Help: Count palindromes in a sentence

From Dev

CSS capitalize whole sentence except for a specific string

From Dev

Find specific sentence in a web page using powershell

From Dev

Extract sentence from text containing a specific phrase

Related Related

  1. 1

    Count a occurrence of a specific word in a sentence haskell

  2. 2

    JAVA: I have to write a program to read "sentences" from a file and and then count the number of words and vowels per sentence

  3. 3

    find the occurence of all vowels in a sentence

  4. 4

    Count vowels in a word

  5. 5

    How to separate sentence into array items, by a specific count of words

  6. 6

    Count the number of vowels in an array in PHP

  7. 7

    Printing the vowels and the vowel count in a string

  8. 8

    Count the number of vowels in an array in PHP

  9. 9

    Count the number of sentence

  10. 10

    Count Number of Sentence Ruby

  11. 11

    How can I check how many consonants and vowels there are in a sentence in Java?

  12. 12

    Counting specific words in a sentence

  13. 13

    Program to count evens odds vowels and consonants in a string

  14. 14

    C++ vector and string, count vowels

  15. 15

    Unable to count vowels using java multithreading

  16. 16

    How to specific letter spacing in a sentence

  17. 17

    Count the number of vowels and print them in a manner that string having more vowels come first

  18. 18

    Remove all vowels in a sentence except for those which occur in the beginning of the word in R

  19. 19

    Remove all vowels in a sentence except for those which occur in the beginning of the word in R

  20. 20

    In Python, how do I check the first two letters of each word in a sentence to see if they have vowels in them?

  21. 21

    How to count vowels in a String including which have accent marks?

  22. 22

    Count the vowels in a string including Y if its followed by a consonant

  23. 23

    is there a more efficient way to count how many vowels in a string?

  24. 24

    how to count the words in a sentence in mysql pdo

  25. 25

    At column, Count word in comma-separated sentence

  26. 26

    Python Palindrome Help: Count palindromes in a sentence

  27. 27

    CSS capitalize whole sentence except for a specific string

  28. 28

    Find specific sentence in a web page using powershell

  29. 29

    Extract sentence from text containing a specific phrase

HotTag

Archive