There are many ways to do this. Using a list (set (a)) will create a list that can take a lot of time depending on your set. But, since you only need iterations for a small number of loops, I would use an iterator and a counter:
count = 0 for elem in iter(mySet): count = count + 1 if count == 10: break print elem
This avoids the overhead of creating a long list, and the overhead of having a manual code for loop control is likely to be negligible.
source share