Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What will [x**2 for x in range(3)] produce?

View

What does [x for x in range(5) if x % 2 == 0] produce?

View

What is the output of [(x, y) for x in [1, 2] for y in [3, 4]]?

View

Which list comprehension creates a list of squares for even numbers from 1 to 5?

View

Which syntax is correct for a nested list comprehension?

View

What will [[x for x in range(2)] for y in range(2)] produce?

View

How do you flatten a list of lists using list comprehension?

View

Which of the following can generate a list of characters from a string?

View

What will [x for x in range(4) if x > 2] produce?

View

Can list comprehensions contain conditional expressions?

View

What will [x**2 for x in range(3)] produce?

[0, 1, 2]
[0, 1, 4]
[1, 4, 9]
None

What does [x for x in range(5) if x % 2 == 0] produce?

[1, 3]
[2, 4]
[0, 2, 4]
[1, 2, 3, 4]

What is the output of [(x, y) for x in [1, 2] for y in [3, 4]]?

[(1, 3), (1, 4), (2, 3), (2, 4)]
[(1, 2), (3, 4)]
[(1, 2), (3, 2)]
[(1, 4), (2, 3)]

Which list comprehension creates a list of squares for even numbers from 1 to 5?

[x**2 for x in range(1, 6) if x % 2 != 0]
[x**2 for x in range(1, 6) if x % 2 == 0]
[x*2 for x in range(1, 6)]
[x**2 for x in [2, 4]]

Which syntax is correct for a nested list comprehension?

[x for y in list1 for x in list2]
[x for x in list1 for y in list2]
[y for y in list1]
[x + y for x in list1 for y in list2]

What will [[x for x in range(2)] for y in range(2)] produce?

[[0, 1], [0, 1]]
[[0], [1]]
[0, 1]
[[0, 0], [1, 1]]

How do you flatten a list of lists using list comprehension?

[x for sublist in list for x in sublist]
[x in sublist for sublist in list]
list(x for x in sublist)
x for sublist in list

Which of the following can generate a list of characters from a string?

[char for char in 'hello']
list(char for char in 'hello')
[c for c in list('hello')]
All of the above

What will [x for x in range(4) if x > 2] produce?

[0, 1, 2]
[3]
[2, 3]
[4]

Can list comprehensions contain conditional expressions?

Yes
No