. Advertisement .
..3..
. Advertisement .
..4..
Computers are mostly used to store information and extract information from it. Python is one of the most powerful programming languages. We can use Python to get computers to do most of the routine processes. This post is all about how to convert a List to Lowercase in Python.
The ways to convert a List to Lowercase in Python
Approach 1: Convert a List to Lowercase Using map()
Simply utilize map()
to convert a List into Lowercase in Python. In Python, you can transform a list into Lowercase by using map()
. It’s a very simple process. So, without wasting any time, let’s take a look at the following example:
lst = ["PIzZa","BurGEr","DHOsA"]
var1 = (map(lambda x: x.lower(), lst))
result = list(var1)
print(result)
Result:
['pizza', 'burger', 'dhosa']
Approach 2: Utilize List comprehension
Utilize List comprehension
to convert a List to Lowercase in Python. In Python, you can turn a list into lowercase using list comprehension
. It’s a very simple process. So, without wasting any time, let’s take a look at the following example:
lst = ["PIzZa","BurGEr","DHOsA"] result = [x.lower() for x in lst] print(result)
Result:
['pizza', 'burger', 'dhosa']
Approach 3: Utilize the str.lower()
Another way to convert a List to Lowercase in Python is using str.lower() function.
All capital characters in a given string are simply converted to lowercase characters and the result is returned using the str.lower()
method. Similar to that, this operation is reversed using the str.upper()
technique. The specified list of string elements are iterated using both the for loop and the str.lower()
function.
The for loop and the str.lower()
function are used in the following code to lowercase a list of strings.
s = ["hEllO","iNteRneT","pEopLe"]
for i in range(len(s)):
s[i] = s[i].lower()
print(s)
Output
['hello', 'internet', 'people']
Conclusion
Convert a List to Lowercase in Python is a confusing problem. We hope this blog has helped clear the air around how to do it. If you have more questions about this topic, please leave a comment below. Thank you for reading! We are always excited when one of our posts can provide useful information on a topic like this!
Read more
Leave a comment