C
C
centrin02015-11-22 14:26:18
Python
centrin0, 2015-11-22 14:26:18

How to organize the storage of objects by key?

Good afternoon.
There is a set of objects with unique identifiers.
Objects are stored as a dict, with a set of properties. For example:
obj = {"color": "red", "type":"inner", "id": "WE324"}
You need to store them and retrieve them using a unique key. How to do it?
Previously, they were added to the list and instead of the key there was their serial number in this very list, but refused such a solution.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2015-11-22
@centrin0

objs = {
  "WE324": {"color": "red", "type":"inner"},
  "WE323": {"color": "red", "type":"inner"},
  "WE322": {"color": "red", "type":"inner"},
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question