DeveloperBreeze

Convert Words to Uppercase in List Comprehension

# Define a list of words
words = ['hello', 'world', 'python']

# Use list comprehension to convert words to uppercase
uppercase_words = [word.upper() for word in words]

Related Posts

More content you might like

Cheatsheet
python

Python List Operations Cheatsheet

You can use either list comprehension or the filter() function to remove empty items from a list.

my_list = ["apple", "", "banana", "", "cherry", ""]
my_list = [item for item in my_list if item]
print(my_list)  # Output: ['apple', 'banana', 'cherry']

Oct 24, 2024
Read More
Code
python

Generate List of Even Numbers Using List Comprehension

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!