Comprehensions & Generators · Question 2 · Easy

A comprehension with an if clause keeps only the passing marks (60 or more). How many values does the new list hold?

marks = [45, 72, 38, 90, 66]
print(len([m for m in marks if m >= 60]))
  1. 2
  2. 5
  3. 228
  4. 3
Answer and explanation

Answer: D. 3

Explanation: Only 72, 90 and 66 satisfy m >= 60, so the filtered list has 3 elements. len counts the elements; it does not add them.

Previous: A list comprehension applies a string method to every company name. What does… · Next: A dictionary comprehension maps each number to its square. What is printed?

Practise comprehensions & generators

Try a fresh set of comprehensions & generators questions with an explanation after every answer, free and without signing up: Comprehensions & Generators practice. Or sit a full placement mock test.

More comprehensions & generators questions

More python practice

Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge