To create a dictionary of vowels and consonants in Python, you can iterate over each letter of the alphabet and check if the letter is a vowel or consonant, and then add it to the respective dictionary.
Here's an example code that demonstrates this:
main.py432 chars15 lines
The output of the above code will be:
main.py308 chars3 lines
In the above code, we first initialize a list of vowels and then create empty dictionaries to hold vowels and consonants. We then iterate over each letter of the alphabet and check if the letter is a vowel or consonant, and if it is a vowel, we add it to vowel_dict
, otherwise, we add it to consonant_dict
. Finally, we print both the dictionaries.
gistlibby LogSnag