daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def permutation(s):
  2.    if len(s) == 1:
  3.      return [s]
  4.  
  5.    perm_list = [] # resulting list
  6.    for a in s:
  7.      remaining_elements = [x for x in s if x != a]
  8.      z = permutation(remaining_elements) # permutations of sublist
  9.  
  10.      for t in z:
  11.        perm_list.append([a] + t)
  12.  
  13.    return perm_list
  14.  
  15. print(permutation("123456789"))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top