fork(1) download
  1. from random import randrange
  2.  
  3. def fy_iter(n):
  4. swaps = {}
  5. def getswapval(k):
  6. if k in swaps: return swaps[k]
  7. return k
  8. for i in range(n):
  9. k = randrange(i,n)
  10. yield getswapval(k)
  11. swaps[k] = getswapval(i)
  12. if i in swaps: del swaps[i]
  13.  
  14. for x in fy_iter (10): print(x)
  15.  
Success #stdin #stdout 0.02s 37024KB
stdin
Standard input is empty
stdout
6
4
5
1
9
0
7
8
2
3