Posted By

purefusion on 09/04/09


Tagged


Versions (?)

Python Pre 2.6 Permutation


 / Published in: Python
 

  1. def swap(string, first, second, begin, end):
  2. string[begin] = second
  3. string[end] = first
  4.  
  5.  
  6. def permutate(string, begin = 0):
  7. end = len(string) -1
  8. srange = end - begin
  9. if srange == 1:
  10. print string
  11. else:
  12. for i in range(0, srange):
  13. swap(string, string[begin], string[begin+i], begin, begin+i)
  14. permutate(string, begin+1)
  15. swap(string, string[begin], string[begin+i], begin, begin+i)

Report this snippet  

You need to login to post a comment.