How to convert list values to lowercase in python?

How to convert list values to lowercase in python?

Hello Devs, 

Today we are going to learn how to convert list values to lowercase in python? In this tutorial, you will learn about how to convert uppercase strings into lowercase in python. I will show you how to convert listed items to lowercase in python. I will show you a few examples of converting list values to lowercase strings in python. There are many ways to all of the values of lowercase. I will show you three quick and easy examples to convert list values to lowercase in python.

So let's get started. 

 

Example 1: Using for loop and lower() function

The method lower() function is applied to convert uppercase strings into lowercase characters and return the modified string. In this example, we will convert list values to lowercase for loop and lower() function.

s = ["hEllO","iNteRneT","pEopLe"]
for i in range(len(s)):
    s[i] = s[i].lower()
print(s)

Output

['hello', 'internet', 'people']

 

Example 2: Using the map() Function along with lambda

In Python, there is a function called map() that can be used to work with lists or other collections of items. This function can apply a specific operation to each item in the collection and return the results as a new collection. 
Along with the map() function, you can also create a small and nameless function called a lambda function. This function can take any number of inputs and perform a single operation on them.
We will use the map() function along with lambda function in the following example. 

s = ["hEllO","iNteRneT","pEopLe"]
a = (map(lambda x: x.lower(), s))
b = list(a)
print(b)

Output

['hello', 'internet', 'people']

 

Example 3: Using the Method of List Comprehension

List comprehension method allows you to create a new list by modifying the original list using certain rules. This following code will take an existing list of strings and create a new list with all the strings in lowercase format using list comprehension.

s = ["hEllO","iNteRneT","pEopLe"]
a = [x.lower() for x in s]
print(a)

Output

['hello', 'internet', 'people']

 

I hope it will help you. 
Happy Coding :)

Leave a Comment

Your email address will not be published. Required fields are marked *

Go To Top
×