Maybe I missed something, but I couldn't find an answer to this on SO or the Python docs.
Got curious about what actually happens under the hood when we write the following code:
maybe_smaller_set = set(some_huge_list)
Since sets don't have duplicates, I imagine there's something like a list comprehension or some clever trick (maybe using map() or filter()?) that occurs to avoid iterating over everything in some_huge_list.
So my questions are these:
- How does Python actually do this conversion from a list instance into a set instance?
- And how costly is this conversion in terms of algorithmic complexity (ie, big-O)?