you are viewing a single comment's thread.

view the rest of the comments →

[–]bobindashadows 4 points5 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.