Database in memory

Jeremy Sanders jeremy+complangpython at jeremysanders.net
Mon Apr 9 10:28:55 EDT 2007


Jim wrote:

> I have an application that will maintain an in-memory database in the
> form of a list of lists.  Does anyone know of a way to search for and
> retreive "records" from such a structure?

The dictionary is the obvious way to index things:

# items consist of name and age
data = [
 ['fred', 42],
 ['jim', 16], ...
]

name_index = {}
for item in data:
 name_index[item[0]] = item

>>> name_index['fred']
['fred', 42]

Dictionaries are one of the most useful things in Python. Make sure you know
how to take adavantage of them...

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/



More information about the Python-list mailing list