First of all, my purpose is to randomly get only one element in both known sets. So my original method is firstly intersect two sets. And then randomly pick up a element from the intersected set. But this is foolish, because that I only need a elements but a intersected set.
So I need to find the algorithm of set.intersection().
I compare the cost time between the methods of 'set.intersection()' and 'for{for{}}'. Set.intersection() is more faster than other one(100 times). So using 'for{for{}}' to pick up a randomly elements is not a wise idea.
What's the algorithm behind set.intersection() in python?
set.intersection
is called, then any implementation is free to do it how it feels. You're free to download/look at the source code for any of the implementations to see how they do it... – Comeuppance