Generating all combinations

Mensanator mensanator at aol.com
Tue Jun 2 01:20:16 EDT 2009


On Jun 1, 8:28�pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> On Mon, 01 Jun 2009 17:24:49 -0700, Mensanator wrote:
> > On Jun 1, 6:40�pm, Steven D'Aprano <st... at REMOVE-THIS-
> > cybersource.com.au> wrote:
> >> On Mon, 01 Jun 2009 11:23:35 -0700, Mensanator wrote:
> >> > I believe the name you're looking for is
> >> > combinations_with_replacement. It is one of the features being added
> >> > to 3.1 which should give all the subsets of the Cartesian Product:
>
> >> > permutations_with_replacement: � �product()
> >> > combinations_with_replacement: � �combinations_with_replacement()
> >> > permutations_without_replacement: permutations()
> >> > combinations_without_replacement: combinations()
>
> >> What, no partitions?
>
> > Itertools does partitions?
>
> Er, no. That's why I asked "What, no partitions?" instead of saying
> "Look, itertools also does partitions!"
>
> >>http://en.wikipedia.org/wiki/Partition_of_a_set
>
> > I didn't see any reference to Cartesian Product there.
>
> Wikipedia is the encyclopedia anyone can edit. Go right ahead and put it
> in if you think it needs to be there. While you're at it, there is no
> mention of Cartesian Product in any of
>
> http://en.wikipedia.org/wiki/Permutationshttp://en.wikipedia.org/wiki/Combinations
>
> http://mathworld.wolfram.com/Permutation.htmlhttp://mathworld.wolfram.com/k-Subset.html
>
> either.

You might have better luck with Google.

> Are you sure that permutations and combinations are subsets of
> the Cartesian Product?

Sure looks that way (SQL examples):

Cartesian Product (Permutaions w/replacement)

SELECT B.q, A.p
FROM A, B;

q	p
a	a
a	b
b	a
b	b


Permutaions wo/replacement
SELECT B.q, A.p
FROM A, B
WHERE (((A.p)<>[B].[q]));

q	p
a	b
b	a


Combinations w/replacement

SELECT B.q, A.p
FROM A, B
WHERE (((A.p)>=[B].[q]));

q	p
a	a
a	b
b	b



Combinations wo/replacement

SELECT B.q, A.p
FROM A, B
WHERE (((A.p)>[B].[q]));

q	p
a	b


I couldn't do that if they weren't subsets.


>
> --
> Steven



More information about the Python-list mailing list