LearnFrenzy
Sign in Take a free test

Sets · Exercise 1 of 4

Sets Sets MCQ

  • 15 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen multiple-choice questions on Python sets: creation, uniqueness, order, remove vs discard, set operations, subsets, hashable elements and frozenset. Pick an option to check your answer instantly.

Question 11 Medium

Why is x in big_set usually much faster than x in big_list?

A Sets are sorted, so binary search is used
B Lists are stored on disk
C It is not faster
D A set looks x up by its hash (average O(1)); a list compares items one by one (O(n))
Question page & discussion
Question 12 Medium

What is {1, 2} < {1, 2}?

A True
B TypeError
C None
D False – a proper subset must be smaller
Question page & discussion
Question 13 Medium

After a = {1} and a.union({2}), what is a?

A {1, 2}
B None
C {1} – union() returns a new set
D {2}
Question page & discussion
Question 14 Medium

Which statement about the order of a set's elements is correct?

A Elements are kept in insertion order
B There is no guaranteed order; for strings it can even differ between runs
C Elements are always sorted
D Elements are in reverse insertion order
Question page & discussion
Question 15 Easy

Which expression is a set comprehension?

A [x * 2 for x in nums]
B {x * 2 for x in nums}
C {x: x * 2 for x in nums}
D (x * 2 for x in nums)
Question page & discussion
Up next · Exercise 2Predict the Output15 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links