Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> the glaring shortcoming which is that, since dictionary keys are required to be hashable, Python has the bizarre situation where dicts cannot be dict keys

There is nothing at all bizarre or unexpected about this. Mutable objects should not be expected to be valid keys for a hash-based mapping — because the entire point of that data structure is to look things up by a hash value that doesn't change, but mutating an object in general changes what its hash should be.

Besides which, looking things up in such a dictionary is awkward.

> More generally, sometimes you have an array, and for whatever reason, it is convenient to use its members as keys.

We call them lists, unless you're talking about e.g. Numpy arrays with a `dtype` of `object` or something. I can't think of ever being in the situation you describe, but if the point is that your keys are drawn from the list contents, you could just use the list index as a key. Or just store key-value tuples. It would help if you could point at an actual project where you encountered the problem.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: