Collection
A utility data structure for python! This enpowers the power of dicts to the next level!
This module is inspired from discordjs collections
Links
Usage
from Collection import Collection
mycol = Collection()
mycol.set('key', 'value')
print(mycol.get('key')) # Prints 'value'!
Properties
col.dict # The data stored in dict
col.size # The size of the dict len(self.dict)
col.keys # Returns the array of keys of dict
col.values # Returns the array of values of dict
col.items # Returns the items of values of dict [(key, value), ...]
Basic methods
col.set(key, value) # Sets a value to the dict
col.get(key) # Returns the value of the key, if no value then returns None
col.clear() # Similar to dict.clear()
col.has(key) # Returns a boolean wheater the key has its value!
Utility methods
col.first() # Returns the first value of the dict
col.first(2) # Returns the array of values of the dict from first to second
col.last() # Returns the last value of the dict
col.last(2) # Returns the array of values of the dict from last to second last
col.random() # Returns a random value of the dict
col.random(2) # Returns a array of 2 random values of dict
# Similar to the above functions there are methods to get the keys of it
col.firstkey() # Returns the first key of the dict
col.firstkey(2) # Returns the array of keys of the dict from first to second
col.lastkey() # Returns the last key of the dict
col.lastkey(2) # Returns the array of keys of the dict from last to second last
col.randomkey() # Returns a random key of the dict
col.randomkey(2) # Returns a array of 2 random keys of dict
Extending a Collection
Extend the collection
col1 = Collection()
col2 = Collection()
col1.set('key', 'value')
col2.extend(col1)
print(col2.get('key')) # Will return value
Will work with dicts too
col = Collection()
col.extend({ 'key': 'value' })
print(col.get('key')) # Will return value
Cloning
Will return a duplicate collection of the current collection
print(col.clone())
To a object
Convert the collection dict to object
col = Collection()
col.set('key', 'value')
obj = col.to_object()
print(obj.key) # Returns value
List methods
Find
Find an item in the items of dict
def find(key, value):
return key == 'key'
print(col.find(find)) # Returns an item (key, value)
Some
Verifies if the callback satisfies any of the items in the dict
def some(key, value):
return key == 'key'
print(col.some(some)) # Returns boolean stating the existence of the key which satisfies the callback
Find
Find an item in the items of dict
def find(key, value):
return key == 'key'
print(col.find(find)) # Returns an item (key, value)
FindMany
Find array of items which satisfies the callback
def findmany(key, value):
return key == 'key'
print(col.findmany(findmany)) # Returns an array of items (key, value)
Sweep
Removes the item of the dict which satisfies the callback
def sweep(key, value):
return key == 'key'
print(col.sweep(sweep)) # Returns nothing
Filter
Similar to sweep but instead returns a new duplicate collection and filters it
def sweep(key, value):
return key == 'key'
print(col.sweep(sweep)) # Returns a new collection
Sweep
Removes the item of the dict which satisfies the callback
def sweep(key, value):
return key == 'key'
print(col.sweep(sweep)) # Returns an item (key, value)
Maps
Maps the values of the dict and returns a duplicate collection
col.set(1, 5) # Current value = { 1: 5 }
def map(key, value):
return value + 1
print(col.map(map)) # Returns an collection
# Collection with value { 1: 6 }
ForEach
Will run the function on each item
def foreach(key, value):
print(key)
print(col.foreach(foreach)) # Returns an item (key, value)
Concat
Will return a duplicate collection by concatting the both collection
col1 = Collection()
col2 = Collection()
col1.set('key', 'value')
print(col2.concat(col1)) # Will return value
Will work with dicts too
col = Collection()
print(col.extend({ 'key': 'value' })) # Will print value
Metadata
Release files for python-collection 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python-collection-1.0.0.tar.gz | 3.5 kB | Without provenance | Details for python-collection-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_collection-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for python_collection-1.0.0-py3-none-any.whl |
Total release size: 7.0 kB
Release files / python-collection-1.0.0.tar.gz
| Download URL | python-collection-1.0.0.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fdc07fa3661b37e3f705b8777de6aeb5490e29a7b1eb7be5ec7eb8f461e232fc
|
|
BLAKE2b-256 checksum How to use checksums |
a850c441bf3946b2a3bfda0944f86528cfa52609c2e4d130f03a82bc1f897a19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.5.0
|
Release files / python_collection-1.0.0-py3-none-any.whl
| Download URL | python_collection-1.0.0-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
069f0b44c2c6c1422286fcedb2f137d9533fce2c9efce937e85d0fd3ddb0d3d0
|
|
BLAKE2b-256 checksum How to use checksums |
93638cbdb2bbbe9445c2dfd05f6e0abb62efb2af4d4934ca6423fd18ba220897
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.5.0
|
Security for python-collection 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.