Package: python-collection
CollectionA utility data structure for python! This enpowers the power of dicts to the next level!This module is inspired from discordjs collectionsLinksGitHubDiscord Support ServerUsagefromCollectionimportCollectionmycol=Collection()mycol.set('key','value')print(mycol.get('key'))# Prints 'value'!Propertiescol.dict# The data stored in dictcol.size# The size of the dict len(self.dict)col.keys# Returns the array of keys of dictcol.values# Returns the array of values of dictcol.items# Returns the items of values of dict [(key, value), ...]Basic methodscol.set(key,value)# Sets a value to the dictcol.get(key)# Returns the value of the key, if no value then returns Nonecol.clear()# Similar to dict.clear()col.has(key)# Returns a boolean wheater the key has its value!Utility methodscol.first()# Returns the first value of the dictcol.first(2)# Returns the array of values of the dict from first to secondcol.last()# Returns the last value of the dictcol.last(2)# Returns the array of values of the dict from last to second lastcol.random()# Returns a random value of the dictcol.random(2)# Returns a array of 2 random values of dict# Similar to the above functions there are methods to get the keys of itcol.firstkey()# Returns the first key of the dictcol.firstkey(2)# Returns the array of keys of the dict from first to secondcol.lastkey()# Returns the last key of the dictcol.lastkey(2)# Returns the array of keys of the dict from last to second lastcol.randomkey()# Returns a random key of the dictcol.randomkey(2)# Returns a array of 2 random keys of dictExtending a CollectionExtend the collectioncol1=Collection()col2=Collection()col1.set('key','value')col2.extend(col1)print(col2.get('key'))# Will return valueWill work with dicts toocol=Collection()col.extend({'key':'value'})print(col.get('key'))# Will return valueCloningWill return a duplicate collection of the current collectionprint(col.clone())To a objectConvert the collection dict to objectcol=Collection()col.set('key','value')obj=col.to_object()print(obj.key)# Returns valueList methodsFindFind an item in the items of dictdeffind(key,value):returnkey=='key'print(col.find(find))# Returns an item (key, value)SomeVerifies if the callback satisfies any of the items in the dictdefsome(key,value):returnkey=='key'print(col.some(some))# Returns boolean stating the existence of the key which satisfies the callbackFindFind an item in the items of dictdeffind(key,value):returnkey=='key'print(col.find(find))# Returns an item (key, value)FindManyFind array of items which satisfies the callbackdeffindmany(key,value):returnkey=='key'print(col.findmany(findmany))# Returns an array of items (key, value)SweepRemoves the item of the dict which satisfies the callbackdefsweep(key,value):returnkey=='key'print(col.sweep(sweep))# Returns nothingFilterSimilar to sweep but instead returns a new duplicate collection and filters itdefsweep(key,value):returnkey=='key'print(col.sweep(sweep))# Returns a new collectionSweepRemoves the item of the dict which satisfies the callbackdefsweep(key,value):returnkey=='key'print(col.sweep(sweep))# Returns an item (key, value)MapsMaps the values of the dict and returns a duplicate collectioncol.set(1,5)# Current value = { 1: 5 }defmap(key,value):returnvalue+1print(col.map(map))# Returns an collection# Collection with value { 1: 6 }ForEachWill run the function on each itemdefforeach(key,value):print(key)print(col.foreach(foreach))# Returns an item (key, value)ConcatWill return a duplicate collection by concatting the both collectioncol1=Collection()col2=Collection()col1.set('key','value')print(col2.concat(col1))# Will return valueWill work with dicts toocol=Collection()print(col.extend({'key':'value'}))# Will print value