Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is There an Already Made Alphabet List In Python?

Tags:

python

I need to create random word/names with random.choice(alphabet) for many of my games in repl, but it is a pain to type it out, and make uppercase versions, consonants/vowels only, etc.

Is there a built-in or importable way to get a pre-made one in python?

like image 886
Frasher Gray Avatar asked Dec 17 '22 15:12

Frasher Gray


1 Answers

The string module provides several (English-centric) values:

>>> import string
>>> string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'
>>> string.ascii_uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> string.digits
'0123456789'

You'll have to create your own vowel/consonant lists, as well as lists for other languages.

Given how short the list of vowels is, vowels and consonants aren't too painful:

>>> vowels = set("aeiou")
>>> set(string.ascii_lowercase).difference(vowels)
{'b', 'f', 'v', 'q', 's', 'w', 'y', 'l', 'g', 'j', 'z', 'c', 'h', 'p', 'x', 'd', 'm', 'n', 't', 'k', 'r'}
like image 73
chepner Avatar answered Dec 28 '22 11:12

chepner