On 19 Ago, 08:40, Frederic Rentsch <anthra.nor...@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 > > Frederic
Yes, maybe the example is silly, but situations like this arise frequently and it's good to know. Thanks for the answers. Ernest -- http://mail.python.org/mailman/listinfo/python-list