List and dictionary comprehensions
A list comprehension creates a new list in a single line: [n * n for n in numbers]. It is shorter than a for loop with .append().
You can add a filter with if: [n for n in numbers if n % 2 == 0] keeps only the even numbers. The same idea exists for dictionaries: {word: len(word) for word in words}.
numbers = [1, 2, 3, 4, 5, 6]
squares = [n * n for n in numbers]
print(squares)
evens = [n for n in numbers if n % 2 == 0]
print(evens)
lengths = {word: len(word) for word in ["hi", "python"]}
print(lengths)