Convert except: StopIterations to simple for loops (Pythonic!)
Use random.choice+tuple instead of random.sample for sets (faster, cleaner)