Initialize the list with alphabets using string.ascii_uppercase
The most pythonic and latest way to perform this particular task. Using this new inbuilt function will internally handle the coding part providing a useful shorthand for the user.
Note: You can use lowercase instead of uppercase to generate lower alphabets.
Python3
import string # initializing empty list test_list = [] # using string for filling alphabets test_list = list (string.ascii_uppercase) # printing resultant list print ( "List after insertion : " + str (test_list)) |
Output :
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