logoalt Hacker News

morshu9001last Thursday at 6:39 PM1 replyview on HN

tuple(sorted(s)) and if you can't even sort the values, they're probably not hashable. I get that this involves a copy, but so does frozenset, and you can cross that bridge in various ways if it's ever a problem.


Replies

boothbylast Thursday at 7:46 PM

Here are some types that support hashing:

  str
  bytes
  int, float
  complex
  tuple
  frozenset
Aside from int and float, you cannot perform comparisons between objects of different types. Moreover, you cannot sort complex numbers at all.

I have crossed that bridge, and I'm telling you (again) that a sorted tuple is not a generic solution.

show 1 reply