expression in an if statement
nfdisco at gmail.com
Fri Aug 20 01:39:10 CEST 2010
On 19 Ago, 08:40, Frederic Rentsch <anthra.nor... at bluewin.ch> wrote:
> 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
Yes, maybe the example is silly, but situations like this arise
frequently and it's good to know.
Thanks for the answers.
More information about the Python-list