A data-structure for 1:1 mappings in python?

前端 未结 8 1505
广开言路
广开言路 2020-12-17 08:17

I have a problem which requires a reversable 1:1 mapping of keys to values.

That means sometimes I want to find the value given a key, but at other times I want to

8条回答
  •  一生所求
    2020-12-17 08:23

    The other alternative is to make a new class which unites two dictionaries, one for each > kind of lookup. That would most likely use up twice as much memory as a single dict.

    Not really, since they would just be holding two references to the same data. In my mind, this is not a bad solution.

    Have you considered an in-memory database lookup? I am not sure how it will compare in speed, but lookups in relational databases can be very fast.

提交回复
热议问题