Rayne
Rayne

Reputation: 14997

Getting the same "key" for a tuple (Python)

I have a tuple that is (a, b, c). I want to get a common value to use as a key from this tuple, and I thought of something like hashing. For example, (a, b, c) and (b, a, c) should both give me the same hash value. However, I tried to hash (1, 2, 3) and (2, 1, 3) and ended up with different hash values.

How do I do this?

Upvotes: 0

Views: 50

Answers (1)

Ryan Asperger
Ryan Asperger

Reputation: 40

How about sort the tuple first? All permutations would become the same tuple after sorting and thus give the same hash value.

Upvotes: 1

Related Questions