Skip to content

Instantly share code, notes, and snippets.

@sing1ee
Created July 11, 2012 02:08
Show Gist options
  • Save sing1ee/3087500 to your computer and use it in GitHub Desktop.
Save sing1ee/3087500 to your computer and use it in GitHub Desktop.
permutation dfs
# !/usr/bin/python
# -*- encoding: utf-8 -*-
string_list = ['a', 'b', 'c', 'd', 'e']
used = [0, 0, 0, 0, 0]
def dfs_permutation(permu, l):
if l == 3:
print permu
for i in range(len(string_list)):
if 0 == used[i]:
used[i] = 1
dfs_permutation(permu + string_list[i], l + 1)
used[i] = 0
dfs_permutation('', 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment