frozenset question

George Sakkis gsakkis at rutgers.edu
Wed Jul 6 13:15:31 EDT 2005


"Steven D'Aprano" <steve at REMOVETHIScyber.com.au> wrote:

> On Wed, 06 Jul 2005 14:25:30 +0100, Will McGugan wrote:
> > No need for the 'premature optimization is the root of all evil' speech.
> > I'm not trying to optimize anything - just enquiring about the nature of
> > frozenset. If typing 'frozenset' over 'set' gave me a saving in time or
> > memory (even if tiny) I would favour immutable sets, where appropriate.
>
> Well, obviously the "premature optimization" speech just went in one ear
> and out the other. "Saving in time or memory" is what optimization is
> about. What did you think optimization means?
>
> set and frozenset have different functionality (one is mutable, the other
> is not) and use cases (you use one where you need to dynamically add and
> remove items from a set, and the other where you need to use a set as a
> key in a dictionary). In most cases, they aren't interchangable.

Well, they *may* be interchangable under some conditions, and that was
the OP's point you apparently missed. If you don't need to dynamically
modify a set and don't add sets as keys in dictionaries, you currently
have a choice; both frozenset and set will work. So all other things
being equal, it makes sense to ask about the relative performance if
the only 'evil' it may introduce can be rectified in a single import.

George




More information about the Python-list mailing list