Please improve these comprehensions (was meaning of [ ])

Ben Bacarisse ben.usenet at bsb.me.uk
Wed Sep 6 18:26:10 EDT 2017


Gregory Ewing <greg.ewing at canterbury.ac.nz> writes:

> Seems to me you're making life difficult for yourself (and
> very inefficient) by insisting on doing the whole computation
> with sets. If you want a set as a result, it's easy enough
> to construct one from the list at the end.

Yes, but my intent was to show that the pattern -- derived from counting
choices -- transfers to the construction of choices, even when sets are
used in place of lists.  I was responding to what I thought was the idea
that you can't work with sets in the same way.

And I see I messed a place where I should have used a set but that's
just stylistic.  Converting the list-of-list version to a set of
(frozen) sets is about twice as fast.

-- 
Ben.



More information about the Python-list mailing list