"Nicolas Dumazet" <nicdumz(a)gmail.com> said:
Good, very nice catch =)
A small note here: set is not really meant to be used on incremental
.add(), because sets are frozen (not mutable), and add() instantiates
a new set on each .add() action. Sets are useful for set operations
(union, intersection), but are not really helpful when it comes to
incrementally construct them. When I need performance for such kind of
lookups, a simple dictionary is usually way faster than sets :) I
would suggest using a dictionary here :)
A dict works fine, but to be pedantic about it, sets *are* mutable. If you
want a non-mutable set, use the frozenset() type.
http://docs.python.org/library/stdtypes.html#set-types-set-frozenset
Russ