List Comprehension Flashcards
1
Q
How would you create the list [0, 1, 2, 3, 4] using list comprehension in Python?
A
arr = [i for i in range(5)]
2
Q
How would you double each value in a list using list comprehension in Python?
A
arr = [i + i for i in range(5)]
Result will be [0, 2, 4, 6, 8]