Skip to content

Instantly share code, notes, and snippets.

@Cerebro92
Created May 22, 2019 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cerebro92/0d3631bf205b206d88cd08f108068601 to your computer and use it in GitHub Desktop.
Save Cerebro92/0d3631bf205b206d88cd08f108068601 to your computer and use it in GitHub Desktop.
List Permutations
import copy
final = []
def main(Arr, res):
if not Arr:
final.append(res)
return
for elem in Arr:
A = copy.deepcopy(Arr)
if res is None:
local_res = [elem]
else:
local_res = copy.deepcopy(res)
local_res.append(elem)
A.remove(elem)
main(A, local_res)
if __name__ == '__main__':
main([1, 2, 3, 4], None)
print final
print len(final)
@Cerebro92
Copy link
Author

Run with python 2.7

-- python permutation.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment