Skip to content

Instantly share code, notes, and snippets.

@bbookman
Created December 26, 2018 21:54
Show Gist options
  • Save bbookman/7d09a66ffdec60d5a55d167751f64175 to your computer and use it in GitHub Desktop.
Save bbookman/7d09a66ffdec60d5a55d167751f64175 to your computer and use it in GitHub Desktop.
Python List Comprehension: Consonants in a string
'''
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, " "']
@Abhay123kumar
Copy link

thanks

@olusegunoyeleke
Copy link

sentence = "Yellow Yaks like yelling and yawning and yesturday they yodled while eating yuky yams"
consonant = [consonant for consonant in sentence if consonant.lower() not in "aeiou" and consonant !=" "]
print(f"{consonant}")

@onrcn-tnrkl
Copy link

vowels = "aeıioöuüAEIİOÖUÜ"
text="Yellow Yaks like yelling and yawning and yesturday they yodled while eating yuky yams"
consontants=[i for i in text if i not in vowels]
print(consontants)

@manal03
Copy link

manal03 commented Jan 10, 2025

result = [x for x in stri.lower() if x not in ['a','e','i','o','u', ' ']]

@darkstrings
Copy link

const_list = [l for l in y_string if l.upper() not in ["A","E","I","O","U"," "]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment