Apply a Title Case to each Element in a Python List

Here are 3 ways to apply a title case to each element in a Python list (special case of apostrophes is included):

(1) Using List Comprehension:

my_list = ["red color", "blue color", "green color"]
title_list = [i.title() for i in my_list]

print(title_list)

As highlighted in yellow, a title case was applied to each element in the list:

['Red Color', 'Blue Color', 'Green Color']

(2) Using For Loop:

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

title_list = []

for i in my_list:
    title_list.append(i.title())

print(title_list)

Here are the same results:

['Red Color', 'Blue Color', 'Green Color']

(3) Special case of apostrophes for example:

import string

my_list = ["red's color", "blue's color", "green's color"]
title_list = [string.capwords(i) for i in my_list]

print(title_list)

The result:

["Red's Color", "Blue's Color", "Green's Color"]

Using a Generator

Optionally, you may use the following generator to apply a title case to each element in a list:

Enter List Name: Enter List Values: Enter New List Name:

For example:

Apply a Title Case to each Element in a Python List