Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arthurmoreno/setdict
Python dict-like interface for merging dicts with add to set property
https://github.com/arthurmoreno/setdict
dictionary key-value merge merge-dict
Last synced: 12 days ago
JSON representation
Python dict-like interface for merging dicts with add to set property
- Host: GitHub
- URL: https://github.com/arthurmoreno/setdict
- Owner: arthurmoreno
- License: mit
- Created: 2018-05-07T18:05:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-14T23:03:06.000Z (almost 6 years ago)
- Last Synced: 2024-07-14T20:04:56.273Z (4 months ago)
- Topics: dictionary, key-value, merge, merge-dict
- Language: Python
- Homepage:
- Size: 10.7 KB
- Stars: 14
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# SetDict
[![PyPI version](https://badge.fury.io/py/set-dict.svg)](https://badge.fury.io/py/set-dict)
![Test Coverage](coverage.svg)If you want to merge Python Dicts into a single one, but want some keys to have set property (but remains as a list). Than this package is for you.
The add_to_set method in SetDict class is very similar to MongoDB $AddToSet command.
## Instalation
Just install with pip
```
pip install set-dict
```## Usage
Supose that you have this three dictionaries:
```
dictA = {
'id': 0,
'weapons': ['sword', 'spear']
}dictB = {
'id': 0,
'weapons': ['bow', 'crossbow'],
'equipments': ['cloak']
}dictC = {
'id': 0,
'equipments': ['hood']
}
```To merge this dicts just make:
```
>>> from setdict.dictmerge import dictmerge
>>> dict_list = [dictA, dictB, dictC]
>>> merged_dict = dictmerge(dict_list)
>>> merged_dict{
'id': 0,
'weapons': ['bow', 'crossbow', 'spear', 'sword'],
'equipments': ['cloak', 'hood']
}```