General question about Python design goals
Fredrik Lundh
fredrik at pythonware.com
Thu Dec 1 12:45:00 EST 2005
Rocco Moretti wrote:
>>>I'm sure Antoon wouldn't object if lists were to be allowed as
>>>dictionary keys, which would eliminate the multiple castings for
>>>that situation. I wouldn't, either.
>>
>> so what algorithm do you suggest for the new dictionary im-
>> plementation?
>
> <devil's_advocate> One option is to create a new "frozen list" type, a`
> la frozen sets.
doesn't frozenset make a copy?
> People who argue that "frozen list" is not needed because we already
> have the tuple type, while simultaneously arguing that tuples shouldn't
> grow list methods because they are conceptually different from lists
> will be bludgeoned to death with a paradox.
http://www.python.org/peps/pep-0351.html
This PEP describes a simple protocol for requesting a frozen,
immutable copy of a mutable object. It also defines a new
built-in function which uses this protocol to provide an
immutable copy on any cooperating object.
...
Here are some code samples which show the intended semantics
class xset(set):
def __freeze__(self):
return frozenset(self)
class xlist(list):
def __freeze__(self):
return tuple(self)
...
</F>
More information about the Python-list
mailing list