Antoon Pardon wrote:
As you said yourself, people use shortcuts when they express themselves.
With 'mutable key' I mean a mutable object that is used as a key.
That doesn't contradict that the key itself can't change because
it is inaccessible.
Yeah - this was the point of terminology that was gett
David Eppstein wrote:
Yes, and what should the following do?
lst1 = [1]
lst2 = [2]
dct = {lst1: "1", lst2: "2"}
lst2[0]=1
lst1[0]=2
print dct[[1]]
print dct[[2]]
Provide yet another example for why mutable keys are almost guaranteed to result
in suprising semantics :)
Cheers,
Nick.
--
Nick Coghla
In article <[EMAIL PROTECTED]>,
Nick Coghlan <[EMAIL PROTECTED]> wrote:
> For a 'mutable key' to make sense, the following:
>
> lst = []
> dct = {l: "Hi!"}
> print dct[[]]
> print dct[lst]
> lst.append(1)
> print dct[[1]]
> print dct[lst]
>
> Should print:
> Hi
> Hi
> Hi
> Hi
Yes, and what sho
Nick Coghlan wrote:
For a 'mutable key' to make sense, the following:
lst = []
dct = {l: "Hi!"}
print dct[[]]
print dct[lst]
lst.append(1)
print dct[[1]]
print dct[lst]
Should print:
Hi
Hi
Hi
Hi
And here's an implementation that does so:
py> class sillydict(dict):
... def __getitem__(self, key)
David Eppstein wrote:
In article <[EMAIL PROTECTED]>,
Nick Coghlan <[EMAIL PROTECTED]> wrote:
For a 'mutable key' to make sense, the following:
lst = []
dct = {l: "Hi!"}
print dct[[]]
print dct[lst]
lst.append(1)
print dct[[1]]
print dct[lst]
Should print:
Hi
Hi
Hi
Hi
Yes, and what should the fo
Op 2005-01-19, Nick Coghlan schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>> A rule of thumb is context sensitive. If circumstances change,
>> so do the rules of thumb. Principles have a broader field
>> of application.
>>
>> IMO there is nothing principally wrong with using a mutable object
In article <[EMAIL PROTECTED]>,
Nick Coghlan <[EMAIL PROTECTED]> wrote:
> Antoon Pardon wrote:
> > A rule of thumb is context sensitive. If circumstances change,
> > so do the rules of thumb. Principles have a broader field
> > of application.
> >
> > IMO there is nothing principally wrong with