Created
August 6, 2010 02:26
-
-
Save brendanberg/510742 to your computer and use it in GitHub Desktop.
Counts vowels and consonants from stdin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, string | |
def vowels(str): | |
count = 0 | |
for let in str: | |
if let in list("AEIOUaeiou"): | |
count += 1 | |
return count | |
def vowelies(str): | |
count = 0 | |
for let in str: | |
if let in list("AEIOUYaeiouy"): | |
count += 1 | |
return count | |
def consonants(str): | |
count = 0 | |
for let in str: | |
if let in list("BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz"): | |
count += 1 | |
return count | |
if __name__ == "__main__": | |
lines = sys.stdin.readlines() | |
vowel_list = map(vowels,lines) | |
consonant_list = map(consonants, lines) | |
vowely_list = map(vowelies, lines) | |
print("%d vowels" % reduce(lambda(x,y):x+y,vowel_list)) | |
print("%d vowels (with Y)" % reduce(lambda(x,y):x+y,vowely_list)) | |
print("%d consonants" % reduce(lambda(x,y):x+y,consonant_list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment