expression in an if statement
Frederic Rentsch
anthra.norell at bluewin.ch
Thu Aug 19 02:40:08 EDT 2010
On Thu, 2010-08-19 at 00:12 +0200, Thomas Jollans wrote:
> On Wednesday 18 August 2010, it occurred to John Nagle to exclaim:
> > On 8/18/2010 11:24 AM, ernest wrote:
> > > Hi,
> > >
> > > In this code:
> > >
> > > if set(a).union(b) == set(a): pass
> > >
> > > Does Python compute set(a) twice?
> >
> > CPython does. Shed Skin might optimize. Don't know
> > about Iron Python.
>
> I doubt any actual Python implementation optimizes this -- how could it?
And why should it if a programmer uses its facilities inefficiently. I
would write
>>> if set(a).issuperset (b): pass
Frederic
More information about the Python-list
mailing list