Skip to main content

Lists with extended / enhanced in-place capabilities - using a new operator notation, closely resembling mathematical conditions

Project description

This library in particular comprises the 'EnhList' class, which is a list with extended / enhanced IN-PLACE capabilities.

Together with the 'elem' term, some of its methods (also) allow using a NEW OPERATOR NOTATION, closely resembling mathematical conditions.

( Note that '&' resp. '|' are 'abused' as 'logical resp. or' in this context (and NOT bitwise!) ).

Examples for said ADDITIONAL capabilities (standard list operations work too) are:

#convert a parameter list to an enhanced list eL = EnhList(1,3,5,7) #eL: [1,3,5,7]

#push single as well as multiple elements into the list eL.push(9) ==> None #eL: [1,3,5,7,9] eL.push(11,13,15) ==> None #eL: [1,3,5,7,9,11,13,15]

#pop single as well as multiple elements from the list - #note that push/pop implements a FIFO - in contrast to the standard list (LIFO) eL.pop() ==> 1 #eL: [3,5,7,9,11,13,15] eL.pop( (elem > 3) & (elem < 11), single ) ==> 5 #eL: [3,7,9,11,13,15] eL.pop( (elem > 3) & (elem < 11) ) ==> [7,9] #eL: [3,11,13,15]

#get items from list eL[ elem >= 10 ] ==> [11,13,15] #eL: unchanged eL[ elem >= 10, single ] ==> 11 #eL: unchanged eL[ elem < 3, single ] ==> None #eL: unchanged

#check whether list contains items ( elem < 3 ) in eL ==> False #eL: unchanged ( elem >= 3 ) in eL ==> True #eL: unchanged

#delete items from list del eL[ elem < 12, single ] ==> --- #eL: [11,13,15] del eL[ elem > 12 ] ==> --- #eL: [11]

eL = EnhList(1,3,5,7) #eL: [1,3,5,7] #check whether all element meet a condition eL.areAll( elem % 2 == 1 ) ==> True #eL: unchanged eL.areAll( elem >= 3 ) ==> False #eL: unchanged

#map function on elements / work with items of elements eL.mapIf( lambda x: dict(a=x) )
==> None #eL: [{'a':1},{'a':3},{'a':5},{'a':7}] eL.mapIf( lambda x: x['a'] + 1, elem['a'] > 3)
==> None #eL: [{'a':1},{'a':3},6,8]

#work with attributes of elements class Attr(object): def init(self, value): self.a = value def repr(self): return ".a=%s" % self.a eL.mapIf( lambda x: Attr(x), lambda x: type(x) == int ) ==> None #eL: [{'a':1},{'a':3},.a=6,.a=8]

More examples can be found in the source code of the selftest function of the module and the methods called from there.

Please take the doc/help-texts of each revised mlist ethod into account too.

Also note, that 'elem' just is an alias defined as follows:

elem = ConditionFunction(lambda x: x)

Meaning that more informations about 'elem' also can be found in the doc/help-text belonging to the class 'ConditionFunction', which, by the way, is inherited from functools.partial.

Further infomations and links can be found on my homepage (see the link on the left hand).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

enhaaancedLists-0.70-py2.py3-none-any.whl (15.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page