How do python Set Comprehensions work?
问题 Q1 - Is the following a set() of a generator expression or a set comprehension ? (Or are they same? If so, are list & dict comprehensions also corresponding type-cast on generators?) my_set = {x for x in range(10)} Q2 - Does the evaluation consider duplicate values & then remove them by applying set() ? dup_set = {x for x in [0, 1, 2, 0, 1, 2]} Does the comprehension perform (speed-wise) better than regular for loops? Update - I tried using timeit for speed comparisons. Am not sure if I am