I want to create a map from objects of the square called MyObject as integers. I've read some stuff but have not understood anything And it does not seem that I want enough. The hash function can be used only for collision, what I have to do, give the object as argument and get the value (integer). Basically what I see is a function (in mathematical terms) in integer with my object.
It seems that this is my class definition:
class MyObject: def __init__ (auto, number): self.name = name self.marked = False < For example a = MyObject ("object 1") b = MyObject ("Object 2") P> Now I should do some mapping, like I can allocate from 25 to one and 36 to B. And be able to get: f (a) = 25 f (b) = 36
I do not fully understand the yor question. My explanation is that you want to use objects in some integer indices. If this is the intention, you can use dict. MyClass: # Your code c1 = MyClass () c2 = MyClass () d = dict ({C1: 1, c2: 2}) d [c 1] # back 1d [ C2] # back2
No comments:
Post a Comment