[Python-ideas] Support multiplication for sets

Guido van Rossum guido at python.org
Sat Oct 8 03:02:35 CEST 2011


On Fri, Oct 7, 2011 at 5:23 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> (2) Cartesian product is potentially very expensive. The Cartesian product
> of a moderate-sized set and another moderate-sized set could turn out to be
> a HUGE set.
>
> This is not a fatal objection, since other operations in Python are
> potentially expensive:
>
> alist*10000000
>
> but at least it looks expensive. You're multiplying by a big number, of
> course you're going to require a lot of memory. But set multiplication can
> very easily creep up on you:
>
> aset*bset
>
> will have size len(aset)*len(bset) which may be huge even if neither set on
> their own is. Better to keep it as a lazy iterator rather than try to
> generate a potentially huge set in one go.

I'm not defending the Cartesian product proposal, but this argument is
just silly. What if the first example was written

alist * n

? Does that look expensive?

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list