[Python-3000] Python-3000 Digest, Vol 2, Issue 151

Nick Coghlan ncoghlan at gmail.com
Thu Apr 27 15:11:13 CEST 2006

Guido van Rossum wrote:
> On 4/26/06, Antoine Pitrou <solipsis at pitrou.net> 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.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-3000 mailing list