Hash() and (un)hashable type: set()

Is my analysis correct?

unhashable set():
(We are aware that) the location of elements in a set() is interchangeable. However, the concealed hash function’s rule is ‘unhashable’ on set() in programming languages.

For example, we know that {1, 2} is equivalent to {2, 1}.
Nevertheless, the Python language violates the hash function(invisible rule) when it iterates through a set {a1, a2,…}, which is a one-to-one function that is “unhashable,” according to my findings.

r = range
# a = {{4*x**2 - 4*x -15} & {x**2 - 5*x - 6} for x in r(-10, 10)}
# print(a)
b = {{x + 1} for x in r(-10, 10)}
print(b)

> > TypeError: unhashable type: 'set'

Hi @LeCorbusier,

I’m confused - is there a Rhino question here?

If you want to discuss Python itself, here are probably better forums.

– Dale

I have explored various platforms, including Python Discourse, YouTube, Udemy, Skillshare, Coursera, and literature. Those resources were largely repetitive and did not assist me in learning the language. If you were to ask how I arrived at this spot, I’m showing my roots: I have been expecting luck to enable me to make advances in Python, even a little progress.

Although I did this in another thread don’t make this a habit. It makes code far harder to read as I pointed out in the very same post I used this.

No need to analyse anything. Just read the documentation on hashable then on set. If you do that carefully you’ll learn that set is a mutable container, and thus not hashable.

Allow an infant to develop in their natural state. :grinning:

Thanks, I found this table. Built-in Functions — Python 3.13.2 documentation
PythonDoc I would never read. I tried, but it doesn’t make sense to me AT ALLLLLoLLLL.

You should start with The Python Tutorial — Python 3.13.2 documentation , and keep the rest of the documentation handy. When you run into things you find strange then search the documentation on that type or issue. The Python docs are extensive, in all likelihood the issue you are trying to find clarity on will have been mentioned.

This is exactly what frozenset is for.

1 Like