https://github.com/olsonpm/py_all-purpose-set
https://github.com/olsonpm/py_all-purpose-set
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/olsonpm/py_all-purpose-set
- Owner: olsonpm
- Created: 2019-01-21T05:01:53.000Z (over 7 years ago)
- Default Branch: dev
- Last Pushed: 2019-05-19T20:19:28.000Z (about 7 years ago)
- Last Synced: 2025-02-22T23:17:20.784Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 171 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# All Purpose Set
**Table of Contents**
- [What is it?](#what-is-it)
- [Why create it?](#why-create-it)
- [Simple usage](#simple-usage)
- [See also](#see-also)
- [Api](#api)
- [Test](#test)
### What is it?
- A set which doesn't require hashable contents
### Why create it?
- I often have a need to store non-hashable contents in a set. For example
storing a dict isn't possible with the builtin set.
```py
# doesn't work
someDict = { "key": "value" }
someSet = { someDict }
```
### Simple usage
```py
from all_purpose_set import ApSet
someDict = { "key": "value" }
someSet = ApSet([someDict])
print(someDict in someSet) # prints True
```
### See also
- [All Purpose Dict](https://github.com/olsonpm/py_all-purpose-dict)
### Api
*Note: This api is young and subject to change quite a bit. There also may be
functionality present in the builtin set which this set doesn't cover. I'm
willing to add it so please just raise a github issue or PR with details.*
#### class ApSet([a list])
- all methods return `self` unless specified otherwise
- iterates in the order of insertion
- currently the internal methods implemented are
- \_\_contains\_\_
- \_\_iter\_\_
- \_\_len\_\_
##### add(something)
##### clear()
##### has(something) => bool
- a function alternative to `key in aSet`
##### remove(something)
- raises a `KeyError` if the element doesn't exist
### Test
```sh
#
# you must have poetry installed
#
$ poetry shell
$ poetry install
$ python runTests.py
```