Guido van Rossum wrote: > On 4/26/06, Antoine Pitrou <[EMAIL PROTECTED]> wrote: >> 1) sets are most often built dynamically rather than statically (in my >> own experience) > > The same is true to the same extent for lists and dicts. > > And yet there are many uses for list and dict literals. > > I've seen a lot of list and tuple literals that should have been sets, > because the main usage was to test whether some value was "in" the > list/tuple or not. That's an O(N) operation -- fortunately it's pretty > fast for tiny N.
Another point in favour of set literals is that they let an optimising compiler play games because the compiler knows that the contents of that literal are supposed to be hashable, even if it can't resolve them right now, and it knows that the result is going to be an actual builtin set object. So the constant-folding part of the optimiser could create the actual set and tuck it away in co_consts if the literal was only used for an "in" test. Those kinds of tricks can't even be contemplated with 'set' because the compiler can't trust that the name is going to resolve to the actual builtin. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com