Created
December 26, 2018 21:54
-
-
Save bbookman/7d09a66ffdec60d5a55d167751f64175 to your computer and use it in GitHub Desktop.
Python List Comprehension: Consonants in a string
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
''' | |
Create a list of all the consonants in the string "Yellow Yaks like yelling and yawning and yesturday they yodled while eating yuky yams" | |
''' | |
sentence = "Yellow Yaks like yelling and yawning and yesturday they yodled while eating yuky yams" | |
result = [letter for letter in sentence if letter not in 'a,e,i,o,u, " "'] |
vowels_space = ['a', 'e', 'i', 'o', 'u', ' ']
sentence = 'Yellow Yaks like yelling and yawning and yesturday they yodled while eating yuky yams'
my_list = [letter for letter in sentence.lower() if letter not in vowels_space]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would just propose to transforme the list in a set to have a unique count of each different consonnant :
IN [ ] :
some_string = "Yellow Yaks like yelling and yawning and yesturday they yodled while eating yuky yams"
voyelles = ["a", "e", "i", "o", "u", "y", " "]
consonnant = [c for c in some_string.lower() if c not in voyelles]
print(set(consonnant))
OUT[ ] : {'g', 'r', 'l', 'w', 'd', 'k', 'h', 's', 'm', 't', 'n'}