# How to use a sequence as dict key?

**URL:** <https://numba.discourse.group/t/how-to-use-a-sequence-as-dict-key/431>\
**Category:** Support: How do I do ...?\
**Created:** [January 13, 2021, 2:31pm UTC](https://numba.discourse.group/t/how-to-use-a-sequence-as-dict-key/431 "2021-01-13T14:31:57Z")\
**Posts on this page:** 1\
**Showing post:** 22

<div class="post-metadata">

**Author:** ![stuartarchibald](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/stuartarchibald/32/10_2.png) [@stuartarchibald](https://numba.discourse.group/u/stuartarchibald)\
**Post date:** [January 27, 2021, 8:28pm UTC](https://numba.discourse.group/t/how-to-use-a-sequence-as-dict-key/431/22 "2021-01-27T20:28:22Z")

</div>

Thanks @luk-f-a.

As queried: [Dynamic, heterogeneous dictionaries with tuple keys and non-constant tuple slicing - #5 by ulupo](https://numba.discourse.group/t/dynamic-heterogeneous-dictionaries-with-tuple-keys-and-non-constant-tuple-slicing/460/5)

> is the idea used in the overloaded `setitem` method of `TupleKeyDict` safe to collisions?

I suggested hashing the tuple here [How to use a sequence as dict key? - #4 by stuartarchibald](https://numba.discourse.group/t/how-to-use-a-sequence-as-dict-key/431/4), what amounts to a suitable hash depends on the use case!

The example I wrote is relying on the hashing implementation for tuples-of-ints. This has been strengthed a lot in recent versions of Python, Numba replicates the algorithm. It’s not guaranteed collision free but in practice may be ok for a given use case. Practically, the values are often bounded and so it may be feasible to just test them all!?

---

_[View the full topic](https://numba.discourse.group/t/how-to-use-a-sequence-as-dict-key/431)._
