Week 2 Unit 8: Self-test

22. October 2024

Question 1

Which of the following statements about list comprehension are correct?

Note: There are 3 correct answers to this question.


List comprehension is a compact way to specify a list. Alternatively, the list could be constructed with a for loop, for example.
Using list comprehension, it is possible to create new lists.
Using list comprehension, it is possible to filter an existing list.
As list comprehension creates a new list, it is written in parenthesis "( )".
List comprehension can only be done if the sequence the list comprehension is based on consists only of integers.

Question 2

week2 unit8 f2

[0, 1, 2, 3, 4]
[2, 4, 6, 8]
[0, 2, 4, 6, 8]
[0, 2, 4, 6, 8, 10]

< Previous unit | Next unit > | Course Overview