List Comprehension Mastery
Intermediate
20 XP
You're trying this as a guest: your result shows here but isn't saved.
Sign in
Master Python list comprehensions — the Pythonic way to transform and filter data.
Tasks:
- Given
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], create squares — a list of the square of each number.
- Create
evens — a list of only the even numbers from numbers.
- Given
words = ['hello', 'world', 'python', 'is', 'awesome'], create lengths — a list of the length of each word.
- Create
long_words — only words with more than 4 characters, uppercased.
Print each result on its own line.
To pass
- Squares of 1-10
- Even numbers from 1-10
- Lengths of each word
- Words > 4 chars uppercased
Need a hint?
- List comprehension syntax: [expression for item in list]
- Add a filter: [expression for item in list if condition]
- Use len(word) to get a word's length, word.upper() to uppercase it.