Initialize the list with alphabets using a naive method
The most general method that comes to our mind is using the brute force method of running a Python loop till 26 and incrementing it while appending the letters in the list. Refer to ASCII Table for more.
Python3
# initializing empty list test_list = [] # printing initial list print ( "Initial list : " + str (test_list)) # using naive method # for filling alphabets alpha = 'a' for i in range ( 0 , 26 ): test_list.append(alpha) alpha = chr ( ord (alpha) + 1 ) # printing resultant list print ( "List after insertion : " + str (test_list)) |
Output :
Initial list : []
List after insertion : [β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β]
Python | Ways to initialize list with alphabets
While working with Python lists, sometimes we wish to initialize the list with the English alphabet a-z or A-Z. This is an essential utility in competitive programming and also in certain applications. Letβs discuss various methods to achieve this using Python.
Contact Us