recursive list comprehension
SimonVC
python at simon.vc
Mon Aug 9 08:02:19 EDT 2004
Is there a way to do this as a list comprehension?
>>> def recu(alist, blist=[]):
... if len(alist)==0: print blist
... for i in range(len(alist)):
... blist.append(alist.pop(i))
... recu(alist, blist)
... alist.insert(i, blist.pop())
>>> recu(list("abc"))
['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
More information about the Python-list
mailing list