Question #602

What is the output of the code snippet below?
print(list({1, 2, 2, 2, 4, 5, 2}))

{1, 2, 2, 2, 4, 5, 2} is a set. It is distinguishable from the curly brackets around it. As {1, 2, 2, 2, 4, 5, 2} is a set, duplicate values are removed first. The first 2 stays while the others are removed. After being transformed to a list, the object becomes [1, 2, 4, 5] . (docs.python.org/2/library/sets.html)


Comment on Disqus:

Question difficulty: ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต