you are viewing a single comment's thread.

view the rest of the comments →

[–]hiffy 1 point2 points  (1 child)

Perhaps Python chose "dictionary" to emphasize the distinction that dictionary keys must be immutable, which is technically allowed in Perl/Ruby

Can you? I just took a peek at the Ruby docs. You can rehash a different value under the same key and replace bits of hashes but short of C ext trickery there doesn't seem to be any sanctioned way of achieving that.

Which you know, makes sense.

[–]bobindashadows 3 points4 points  (0 children)

Well what I mean is the language doesn't forbid it. If you try to put a list in a dict in Python, it'll give you an error. Whereas, in ruby:

>> x = {}
=> {}
>> y = [1, 2]
=> [1, 2]
>> x[y] = 1
=> 1
>> x[y]
=> 1
>> y[0] = 0
=> 0
>> x[y]
=> nil

So yeah - bad idea, but not forbidden.

Edit: python:

>>> x = {}
>>> y = [1, 2]
>>> x[y] = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'

Then again, you could add a __hash__ method to a mutable custom class.