xxxxxxxxxx
import itertools
print(list(itertools.permutations([1,2,3])))
xxxxxxxxxx
import itertools
a = [1, 2, 3]
n = 3
perm_iterator = itertools.permutations(a, n)
for item in perm_iterator:
print(item)
xxxxxxxxxx
from itertools import permutations
a=permutations([1,2,3,4],2)
for i in a:
print(i)
xxxxxxxxxx
from itertools import permutations
string="SOFT"
a=permutations(string)
for i in list(a):
# join all the letters of the list to make a string
print("".join(i))
xxxxxxxxxx
def permute(LIST):
length=len(LIST)
if length <= 1:
yield LIST
else:
for n in range(0,length):
for end in permute( LIST[:n] + LIST[n+1:] ):
yield [ LIST[n] ] + end
for x in permute(["3","3","4"]):
print x
xxxxxxxxxx
def permutations(s):
if len(s) <= 1:
yield s
else:
for i in range(len(s)):
for p in permutations(s[:i] + s[i+1:]):
yield s[i] + p
input = 'ABCD'
for permutation in enumerate(permutations(input)):
print repr(permutation[1]),
print
xxxxxxxxxx
T=[i for i in range(8)]
for i in range(8):
print("T[",i,"]= ",end="")
T[i]=int(input())
print("Tableau avant permutation")
print(T)
k=7
for i in range(4):
X=T[i]
T[i]=T[k]
T[k]=X
k=k-1
print("Tableau après permutation")
print(T)
xxxxxxxxxx
from itertools import permutations
data = ["A", "B", "C"]
perms = permutations(data)
for perm in perms:
print(perm)
xxxxxxxxxx
from itertools import permutations
data = ["A", "B", "C"]
perms = permutations(data)
for perm in perms:
print(perm)