rbt <[EMAIL PROTECTED]> wrote: > Say I have a list that has 3 letters in it: > > ['a', 'b', 'c'] > > I want to print all the possible 4 digit combinations of those 3 > letters: > > 4^3 = 64 > > aaaa > abaa > aaba > aaab > acaa > aaca > aaac > ... > > What is the most efficient way to do this?
Since you're doing cross product (ie. 3*3*3*3), manual loop of 4 level deep would be the fastest in terms of algorithm. C vs. Python is implementation detail. In Bash shell, this is one-liner, echo {a,b,c}{a,b,c}{a,b,c}{a,b,c} or maybe two, abc=(a b c) echo {^abc}{^abc}{^abc}{^abc} -- William Park <[EMAIL PROTECTED]>, Toronto, Canada ThinFlash: Linux thin-client on USB key (flash) drive http://home.eol.ca/~parkw/thinflash.html BashDiff: Super Bash shell http://freshmeat.net/projects/bashdiff/ -- http://mail.python.org/mailman/listinfo/python-list