Jan-16-2020, 09:42 AM
Thank you for the explanation !
You helped me a lot.
I agree NamedTuple is useful here. But what I don't understand is the following sentence from the doc:
And my class
So here the result that I have done and that is working. I will explain my aim in an other post as it would be different that the title of this post. My question of this post was only about why I cannot use a hashable object in a set.
You helped me a lot.
I agree NamedTuple is useful here. But what I don't understand is the following sentence from the doc:
A set object is an unordered collection of distinct hashable objects.
And my class
Building
is Hashable. So why it needs to me immutable in order to be used in a set ? I don't find a clear reference.So here the result that I have done and that is working. I will explain my aim in an other post as it would be different that the title of this post. My question of this post was only about why I cannot use a hashable object in a set.
from dataclasses import dataclass @dataclass(frozen=True, eq=True) class BuildingProperty: stone: int wood: int architecture: int decoration: int victory_point: int money: int @dataclass(frozen=True, eq=True) class Building: name: str properties: BuildingProperty foo = Building(name="Test", properties=BuildingProperty(stone=2, wood=1, architecture=0, decoration=1, victory_point=8, money=4)) var = {foo}