The simplest approaches are recursive, i.e. in executable pseudo code,
def permute(theseq):
if len(theseq) <= 1:
yield theseq
return
for i in range(len(theseq)):
theseq[0], theseq[i] = theseq[i], theseq[0]
for subperm in permute(theseq[1:]):
yield theseq[:1] + subperm
theseq[0], theseq[i] = theseq[i], theseq[0]
, [1:] [:1] "" ( ", " " " ), " 0- i- " " " (.. ;-). yield " , ", return " , !".
, , - . , , , ,
! -)