Example 01: Using Lower() Function
The first method we utilize to convert the python list to lowercase is the python’s lower() function. So, we have opened a new python project in the Spyder3 tool to add a simple code. We have started our python script by initializing a string type list containing all capital alphabets from A to F.
The print statement has been utilized here to print out the list. The “for” loop is initiated here to iterate the list elements using the list length as a range defined for it. While the loop runs, each item of a list “L” would be converted into lowercase and again saved to the same index of a list. After the loop ends, the updated list will be outputted on the console via the print clause once again.
for in in range(len(L)) :
L[i] = L[i].lower()
Let’s make our code run by using the “Run” button of the Spyder3 menu bar. The output shows the original list first and then the updated list with lowercase elements. The result of the above program is displayed here.
Example 02: List Comprehension Method
Our second and very well-known method to convert an uppercase list to a lowercase list is the list comprehension method. To use this method, define some string type list, i.e., “L”. This string type list would be printed out using the same print clause. Now we have to utilize the list comprehension method to convert the list to lowercase.
Within this method, we have used the lower() function in the “for” loop. Every item in the list has been converted to the lowercase, start to end, and saved to the original list. The updated list would then be printed out using the print clause of python. The code is shown below.
L = [s.lower() for s in L]
Run your code once again by the “Run” button of the Spyder3 menu bar. You can see in the image below that it displays the same output as the above example does. It printed out the original list first and then the lowercase list after that. The result of the above program is displayed here.
Example 03: Using Map Function
Another easy and common method in python for converting an uppercase list into a lowercase list is the “map()” function. We have defined a new list “L” in the python code project. It contains 5 string type values in it. Some of the values of this list are the whole uppercase, and some are partial uppercased and partial lowercased. The print clause takes the list “L” in its parameters to output it out on the console. Then we have declared a new string type variable “a”. This variable takes the updated values and saving them.
The list items have been passed to the “lower()” function to be converted into lowercase. The map function is used here to do so by using the lambda feature. The contents have been again converted into a string and saved to the variable “a”. The list type variable “a” has been outputted using the print clause at the end.
a = list(lambda x: x.lower(), L))
After running this code, we have got two lists, i.e., original and updated ones. The result of the above program is displayed here.
This article contains three unique methods to describe and illustrate how a string-type list can be converted into an integer type. Examples are easy, simple, and easy to understand. Use all these above-described methods whenever you are trying to lower case your python list. Thus, we hope this article will be helpful to our users.