Assessment questions for the list comprehension concept map.
Question 1: Given the following list comprehension, what will the resulting output be?
[x**2 for x in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] if x != 0 and x**2 < 10]
- [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
- [1, 4, 9]
- [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
- [0, 1, 4, 9]
Question 2: Which list comprehension would produce the following result?
[‘a’, ‘aa’, ‘aaa’, ‘aaaa’]
- [‘a’ * x for x in range(4)]
- [x for x in [‘a’, ‘aa’, ‘aaa’, ‘aaaa’, ‘aaaaa’] if x < 5]
- [‘a’ * x for x in range(1, 5)]
- [x + ‘a’ for x in [‘a’, ‘aa’, ‘aaa’]]