[Python-ideas] Implementing a set of operation (+, /, - *) on dict consistent with linearAlgebrae

Robert Vanden Eynde robertve92 at gmail.com
Wed Oct 31 15:29:09 EDT 2018


And with libraries like pip install funcoperators or pip install infix, you
can even write it infix :D

from funcoperators import infix
@infix
def superop(d1, sc):
    return {k: (v *superopp* sc) for k, v in d1.items()}

print({'a': 8} *superop* 5)


Le mer. 31 oct. 2018 à 18:35, Vladimir Filipović <hemflit at gmail.com> a
écrit :

> Julien, would I be correct if I summarized the changes you have in
> mind like this:
>
> for dictionaries d1 and d2,
> non-Mapping ("scalar") sc,
> binary operation ⊛,
> and unary operation 𝓊 (such as negation or abs()):
>
> d1 ⊛ sc == {k: (v ⊛ sc) for k, v in d1.items()}
> sc ⊛ d1 == {k: (sc ⊛ v) for k, v in d1.items()}
> 𝓊(d1) == {k: 𝓊(v) for k, v in d1.items()}
> d1 ⊛ d2 == {k: (d1[k] ⊛ d2[k]) for k in d1.keys() & d2.keys()}
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181031/3e16abf7/attachment-0001.html>


More information about the Python-ideas mailing list