I have a list of elements which should be unique by construction. I mean, no element will be present more than once in the list.
I want to efficiently test if an item is present in that list, and this for many items.
The test is more efficient if I convert the list into a set.
Now my questions are about how to efficiently build the set.
I guess that when I do my_set = set(my_list)
, python somehow has to test membership of items in the list as it progressively constructs the set.
Is this sub-optimal given the knowledge that I know that the list does not contain duplicates?
Is it possible to do better?
Does the answer to the question above change if instead of a list, I have an iterator (about which I still know that the items it will yield will be unique)?