Creating combination of sequences
Mike C. Fletcher
mcfletch at rogers.com
Sat Nov 13 14:01:14 EST 2004
Minho Chae wrote:
>Hello, python lovers!!
>
>I'm trying to create combinations of sequences.
>
>
A simple recursive generator should produce what you want while being
fairly easy to read...
>>> def permute( choices, length=8 ):
... if length > 1:
... for suffix in permute(choices,length-1):
... for choice in choices:
... yield choice + suffix
... else:
... for choice in choices:
... yield choice
That's not the same ordering you wanted, but that's merely a matter of
swapping the order of choice and suffix.
HTH,
Mike
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
More information about the Python-list
mailing list