0

Unicode Characters English and Indian Languages

Hello Python Community, I created this program which prints unicode characters of English and Indian Language Characters. https://code.sololearn.com/cQUXAFquw9ww/#py Could please help me in optimising this code? In section 3 to section 10 I have created a empty list named numbers and have been successful in running a for loop to append all numbers in a particular range into the numbers list. It works smoothly and I am happy with this. In section 1 however, I tried the same trick to create an empty list named characters and tried to append them with a for loop for a particular range of characters (not numbers). How is this possible? I was not successful, so I ended up manually typing all english alphabets A to Z in the list named characters to create 26 items. Is there an efficient way to do this?

22nd Jul 2020, 9:37 AM
Expensive Harmonica
Expensive Harmonica - avatar
4 Respuestas
0
@Granger : Thanks. 1. The below line of code is useful characters = list(i for i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ") I did not know that we have to just knock-off the range() from for loop and just for plain string. 2. The use of formatted strings appears to be an efficient way I still have a question. "How to fill an empty list with characters. i.e. let us say I am lazy and I know english alphabet starts with A and ends with Z, I just give these two characters as something like start and stop in a range and it should automatically fill the empty characters list. Suppose, I want to give a start with a lowercase "a" and end with smallercase "z". I do not want to retype the 26 character string. Is there a work around. I am wondering, if in my mother tongue (Tamil) which has 247 characters, "How do I just type the starting alphabet and ending alphabet and add them to the list (with an append method). Thank you once again for your fast response and neat code
22nd Jul 2020, 10:09 AM
Expensive Harmonica
Expensive Harmonica - avatar
0
@Granger : why not use a simple numbers.append() instruction instead of the creating an user defined function called add to append the list def add(x, lst): lst.append(x) # section 2 numbers = list() for number in range(65,91): add(number, numbers) for number in numbers: print (f"The Character for the Unicode value {str(numbers)} is : {chr(number)}")
22nd Jul 2020, 1:03 PM
Expensive Harmonica
Expensive Harmonica - avatar