I love moredots ❤️
With pip install funcoperators, one can implement the *dotmul* iff dotmul can be implemented as a function.
L *dotmul* 1
Or even a simple tweak to the library would allow L *dot* s to be [x*s for x in L] and L /dot/ s to be [x/s for x in L]"
I'd implement something like "if left is iterable and right is not, apply [x*y for x in left] else if both are iterable, apply [x*y for x,y in zip(left, right)] etc."
Disclaimer : I'm the creator of funcoperators
On Fri, 1 Feb 2019, 00:23 Steven D'Aprano <firstname.lastname@example.org wrote:
On Thu, Jan 31, 2019 at 09:51:20AM -0800, Chris Barker via Python-ideas wrote:
I do a lot of numerical programming, and used to use MATLAB and now
lot. So I am very used to "vectorization" -- i.e. having operations that work on a whole collection of items at once.
You can imagine that for more complex expressions the "vectorized"
can make for much clearer and easier to parse code. Also much faster,
is what is usually talked about, but I think the readability is the
Julia has special "dot" vectorize operator that looks like this:
L .+ 1 # adds 1 to each item in L func.(L) # calls f on each item in L
The beauty of this is that you can apply it to any function or operator and the compiler will automatically vectorize it. The function doesn't have to be written to specifically support vectorization.
So what does this have to do with the topic at hand?
I know that when I'm used to working with numpy and then need to do some string processing or some such, I find myself missing this
-- if I want to do the same operation on a whole bunch of strings, why
need to write a loop or comprehension or map? that is:
[s.lower() for s in a_list_of_strings]
Using Julia syntax, that might become a_list_of_strings..lower(). If you don't like the double dot, perhaps str.lower.(a_list_of_strings) would be less ugly.
-- Steven _______________________________________________ Python-ideas mailing list Pythonemail@example.com https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/