Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stuaxo/multidex
Python dictionary with more than one key per item.
https://github.com/stuaxo/multidex
Last synced: about 1 month ago
JSON representation
Python dictionary with more than one key per item.
- Host: GitHub
- URL: https://github.com/stuaxo/multidex
- Owner: stuaxo
- Created: 2015-11-06T13:46:08.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-06T14:41:31.000Z (about 9 years ago)
- Last Synced: 2024-09-13T20:09:22.429Z (2 months ago)
- Language: Python
- Homepage:
- Size: 0 Bytes
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Multidex
Simple Multi Index Dictionaries for python.Dictionary with secondary indexes.
Ideal for many "small data" situations where data fits into memory, and you want a fast lookup for various fields.
Specify extra indexes and their getters then use as a normal dict, to do lookups using the additional fields use the ```find``` method.
Toy example
```python
from collections import namedtuple
from operator import attrgetter
from multidex import MultiIndexHighScore = namedtuple("HighScore", "name score species")
highscores = [
HighScore("terry", 200, "cat"),
HighScore("jill", 1900, "human"),
HighScore("zoooby", 100, "cat"),
HighScore("chilax", 100, "human"),
]class HighScores(object):
__metaclass__ = MultiIndex
alt_indexes = dict(
species=attrgetter("species"),
score=attrgetter("score")
)score_idx = HighScores(**{score.name: score for score in highscores})
print score_idx.find("score", 100)
(HighScore(name='chilax', score=100, species='human'), HighScore(name='zoooby', score=100, species='cat'))
```