【活动】大头& echo8610---广岛之恋(有惊喜噢!)# Music - 天籁之音
r*n
1 楼
# Input: list, the most left index, the most right index
# Output: print all permutations.
def permutation(a, l, r):
if l >= j:
print a
return
for k in xrange(l,r+1):
#swap the first and the Kth
a[l], a[k] = a[k], a[l]
permutation(a,l+1,r)
a[l], a[k] = a[k], a[l]
How to use:
For example: permutation([1,2,3,4], 0, 3)
# Output: print all permutations.
def permutation(a, l, r):
if l >= j:
print a
return
for k in xrange(l,r+1):
#swap the first and the Kth
a[l], a[k] = a[k], a[l]
permutation(a,l+1,r)
a[l], a[k] = a[k], a[l]
How to use:
For example: permutation([1,2,3,4], 0, 3)