-1

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!

eerio
  • 43
  • 2
  • 6
  • What are you trying to do? Pattern matching? Please post the necessary details. – stuckoverflow Mar 13 '21 at 10:22
  • 3
    You've already included this string constant twice in this question. What is the problem with including it in your code? – mkrieger1 Mar 13 '21 at 10:25
  • 2
    Won't ever happen. People wouldn't be able to agree about 'y'. Plus it's just not important. – superb rain Mar 13 '21 at 10:26
  • 2
    What exactly is your usecase? Do you just want to replace the `vowels = "aeiou"` with some import, or do you care about different definitions of "vowel" in different locales? – tobias_k Mar 13 '21 at 11:02

2 Answers2

0

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.

Alain T.
  • 40,517
  • 4
  • 31
  • 51
-1

A vowel list is not in the standard python library, but a quick way generate a vowel list is:

vowels = set("aeiou")

Robin
  • 65
  • 2