Python program to generate a list of alphabets in lowercase
We can use the string module to perform this activity.
The method ascii_lowercase will help us to achieve the list of alphabets in lowercase. So, Let us first import the string module.
import string
Generating the alphabets in lowercase using the method ascii_lowercase.
a = list(string.ascii_lowercase)
print(a)
Below is the output:
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
Let us create a dictionary which contains Keys as alphabets and values as numbers range from 1-26
For this, first we have to initialize the empty dictionary
alpha={}
Now, create a for loop from the range values 0-26
for i in range(0,26):
a = list(string.ascii_lowercase) # this generates the alphabets
alpha.update({a[i]:i+1})
print(alpha)
Below is the output:
{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
Below is the complete code:
import string
alpha={}
for i in range(0,26):
a = list(string.ascii_lowercase)
alpha.update({a[i]:i+1})
print(alpha)
Share: