all possible combinations

mensanator at aol.com mensanator at aol.com
Wed Jul 13 23:59:41 CEST 2005



rbt 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

Should be 3**4 = 81.

>
> aaaa
> abaa
> aaba
> aaab
> acaa
> aaca
> aaac
> ...
>
> What is the most efficient way to do this?

Table t
[c]
a
b
c

Query q
SELECT t_3.c AS c1, t_2.c AS c2, t_1.c AS c3, t.c AS c4
FROM t, t AS t_1, t AS t_2, t AS t_3;

output
[c1]	[c2]	[c3]	[c4]
a	a	a	a
a	a	a	b
a	a	a	c
a	a	b	a
a	a	b	b
a	a	b	c
a	a	c	a
a	a	c	b
a	a	c	c
a	b	a	a
a	b	a	b
a	b	a	c
a	b	b	a
a	b	b	b
a	b	b	c
a	b	c	a
a	b	c	b
a	b	c	c
a	c	a	a
a	c	a	b
a	c	a	c
a	c	b	a
a	c	b	b
a	c	b	c
a	c	c	a
a	c	c	b
a	c	c	c
b	a	a	a
b	a	a	b
b	a	a	c
b	a	b	a
b	a	b	b
b	a	b	c
b	a	c	a
b	a	c	b
b	a	c	c
b	b	a	a
b	b	a	b
b	b	a	c
b	b	b	a
b	b	b	b
b	b	b	c
b	b	c	a
b	b	c	b
b	b	c	c
b	c	a	a
b	c	a	b
b	c	a	c
b	c	b	a
b	c	b	b
b	c	b	c
b	c	c	a
b	c	c	b
b	c	c	c
c	a	a	a
c	a	a	b
c	a	a	c
c	a	b	a
c	a	b	b
c	a	b	c
c	a	c	a
c	a	c	b
c	a	c	c
c	b	a	a
c	b	a	b
c	b	a	c
c	b	b	a
c	b	b	b
c	b	b	c
c	b	c	a
c	b	c	b
c	b	c	c
c	c	a	a
c	c	a	b
c	c	a	c
c	c	b	a
c	c	b	b
c	c	b	c
c	c	c	a
c	c	c	b
c	c	c	c
Record 81 of 81




More information about the Python-list mailing list