Advertisement
boris-vlasenko

перестановки

Sep 21st, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. def rec_permutations(n):
  2.     s = ''
  3.     for i in n:
  4.         s += str(i)
  5.        
  6.     L = []
  7.     if len(s) == 1:
  8.         return [s]
  9.     else:
  10.         for x in s:
  11.             for a in rec_permutations(s.replace(x, "")):
  12.                 L.append(x + a)
  13.         return L
  14.    
  15.  
  16.  
  17. print(
  18.     '\n'.join(
  19.         ' '.join(str_subset) for str_subset in[
  20.             map(str, sorted_subset) for sorted_subset in sorted(rec_permutations("567"))
  21.         ]
  22.     )
  23. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement