Search code examples
pythonpython-3.xalphabet

Python vowels constant


Is there a Python library that contains a variable which contains vowels, e.g. 'aeiou', ['a', 'e', 'i', 'o', 'u'] or something like that? in the string library there is ascii_lowercase variable with the English alphabet, but extracting vowels and consonants from it requires hard-coding the 'aeiou'-like constant. Can we avoid that?

Edit: Answering to questions in comments:
Yes, the use-case is to replace

alphabet = 'abcdefghijklmnopqrstuvwxyz'
vowels = 'aeiou'
consonants = 'bcdfghjklmnpqrstvwxyz'

with something less error-prone. What I use now is:

from string import ascii_lowercase as alphabet
vowels = 'aeiou'
consonants = ''.join(c for c in alphabet if c not in vowels)

But ideally, I would like to be able to just import these constants:

from [lib] import alphabet, vowels, consonants

Thank's for the feedback!


Solution

  • There is no predefined variable for vowels because they are defined based on phonology/pronunciation and vary between language. Some letters are either vowels or consonants depending on their placement in words. Saying that 'aeiou' are vowels is more of a reductive shorthand on the concept than an actual definition. You will need to make your own constant in accordance with your use case.