S
SimonVC
Is there a way to do this as a list comprehension?
.... for i in range(len(alist)):
.... blist.append(alist.pop(i))
.... recu(alist, blist)
.... alist.insert(i, blist.pop())
['a', 'b', 'c']
['a', 'c', 'b']
['b', 'a', 'c']
['b', 'c', 'a']
['c', 'a', 'b']
['c', 'b', 'a']
Cheers
SimonVC
keywords: python recursive permutations algorithm combination jumble
.... if len(alist)==0: print blistdef recu(alist, blist=[]):
.... for i in range(len(alist)):
.... blist.append(alist.pop(i))
.... recu(alist, blist)
.... alist.insert(i, blist.pop())
['a', 'b', 'c']
['a', 'c', 'b']
['b', 'a', 'c']
['b', 'c', 'a']
['c', 'a', 'b']
['c', 'b', 'a']
Cheers
SimonVC
keywords: python recursive permutations algorithm combination jumble