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?
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'}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With