Tobias Weber <towb <at> gmx.net> writes:

> 
> Hi,
> whenever I type an "object literal" I'm unsure what optimisation will do 
> to it.
> 
> def m(arg):
>   if arg & set([1,2,3]):
>     return 4
> 
> Is the set created every time the method is called?

Yes, and the list.

> What about a 
> frozenset?

Yep.

> Or tuple vs list?

Tuples containing other immutable literals can be optimized. (In cpython 
anyway.)

> After how many calls per second does it pay 
> to save it at the module level?

Ask the profiler. Probably not many.

> Would anybody else find this ugly?

I do it all the time. 




-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to