![]() I chose the term “subtractive” because these operations are always taking something away from an input. Intersection and difference always produce a result that is a subset of one of the arguments. I’m handwaving a bit with the terms “additive” and “subtractive”, and any help in refining this termonology would be appreciated, but I believe there is a real mathematical symmetry here that informs what could defaults should be. The item in result1 is the “natural” iteration order, and that corresponds to rightmost priority in the nary operation. > a = ub.SetDict(ĭepending on the order in which you iterate through data, “reduced” (better term?) calls to symmetric difference will result in a different order. implement merge callables so the user can specify how to resolve A heavier extension would be needed for that. Item-wise operations are in general not hashable and therefore not ![]() The SetDict class only defines key-wise set operations. The rights are lists/sets, whereas difference / intersection does. Unpaired union might have been a better name for this, but takeĪlso, union / symmetric_difference does not make sense if arguments on ![]() I'm don't have a greatĪrgument for it, but it seemed easier to implement this way and itĭoes seem closer to a union than it is to a difference. symmetric_difference is somewhat strange. it is basically just an aliasįor dict.update, so the new (rightmost) keys clobber the old.ģ. Other dictionary (or set or list of keys), whereasĢ. To find values in the first (main) dictionary that are also in some intersection / difference is for removing keys - i.e. Symmetric_difference and left-most values take priority in intersectionġ. The reason righmost values take priority in union / Takes the itemsįrom all dictionaries where the key appears an odd number of times. * symmetric_difference (or the ``^`` operator). Takes only items from the firstĭictionary that do not share keys with following dictionaries. Takes the items from theįirst dictionary that share keys with the following dictionaries This is nearly identical to the update operation. * union (or the ``|`` operator) combines multiple dicttionaries into Or via a custom ``merge`` callable similar to _. Right-most priority (default for ``union`` and ``symmetric_difference``), With left-most priority (default for ``intersection`` and ``difference``), Like performing the operation on sets of keys. ![]() I spent a lot of time writing the docs, so I’ll just paste that description: """Ī dictionary subclass where all set operations are defined.Īll of the set operations are defined in a key-wise fashion, that is it is I have a baseline implementation in my ubelt library call SetDict - ubelt.util_dict module - UBelt 1.3.2 documentation I have a strong opinion that dictionaries in Python should have key-based set operations. This post is about my thoughts on extending Python’s dictionary. In that article, I covered various methods for mapping one list onto the other.In another thread ( Scientific Utilities - Contributor & Development Discussion - Scientific Python) I was encouraged to submit some of my ideas to the Python discussion forum. Earlier in this series, I covered a similar problem where I wanted to convert two lists into a dictionary.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |