This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
Extending `dictionary` class
Post Body

I created a class, creatively called dictionary2 which is really just an object which contains two dictionary objects, where values of the first dictionary are the key's of the second, and the keys of the first are the values of the second. This allows very quick reverse look-up, and for my use case (needing to call it millions of times), the speed is important.

Everything works, except my object can't add key/value pairs using the

my_dict(keys) = values;

format, because best I can tell, user defined functions can't use that format. I believe if I extended the dictionary class, there should be a way to do it, but I can't find any examples of how to use that format to both be a constructor, and to serve as an add function.

Currently, I just have worked around this by just creating an add method to my object, and it works but I was hoping I could get it to work so that everywhere in my code I currently have dictionary I could just replace it with dictionary2 and otherwise it be invisible.

If anyone has a suggestion or know where I could look to accomplish this (or tell me it can't be done) that would be great.

Author
Account Strength
100%
Account Age
14 years
Verified Email
Yes
Verified Flair
No
Total Karma
366,660
Link Karma
6,788
Comment Karma
350,314
Profile updated: 6 days ago
Posts updated: 5 months ago
+5

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago