NVIDIA Interview Question

Tell me the difference between Sets, Tuples, and Lists in Python.

Interview Answer

Anonymous

Mar 23, 2020

Sets are an unordered, mutable collection of items, while tuples are an ordered, immutable collection of items. For example, a set of numbers {1, 2, 3} is the same as the set {1, 3, 2} as well as {3, 2, 1}, or {3, 3, 2, 1} (because repeat elements aren't counted). On the other hand, the tuple (1, 2, 3) is completely different from the tuple (1, 3, 2), or (2, 1, 3), and so on. Lists are *essentially* just mutable tuples.