Capitalize the First Letter of each Element in a Python List

Two approaches to capitalize the first letter of each element in a Python list:

(1) Using a List Comprehension:

my_list = ["red color", "blue color", "green color"]

capitalize_list = [i.capitalize() for i in my_list]

print(capitalize_list)

As highlighted in yellow, the first letter of each element in the list is now capitalized:

['Red color', 'Blue color', 'Green color']

Please check the following guide if you wish to apply a title case instead.

(2) Using a For Loop:

my_list = ["red color", "blue color", "green color"]

capitalize_list = []

for i in my_list:
capitalize_list.append(i.capitalize())

print(capitalize_list)

The result:

['Red color', 'Blue color', 'Green color']

Additional resources:

Leave a Comment