On Sat, May 9, 2020 at 11:57 AM Dominik Vilsmeier <[email protected]>
wrote:

> So as a practical step forward, what about providing a wrapper type
> which performs all operations elementwise on the operands. So for example:
>
>      if all(elementwise(chars) == string):
>          ...
>
> Here the `elementwise(chars) == string` part returns a generator which
> performs the `==` comparison element-by-element.
>

Now `==` has returned an object that's always truthy, which is pretty
dangerous.


> This doesn't perform any length checks yet, so as a bonus one could add
> an `all` property:
>
>      if elementwise(chars).all == string:
>          ...
>

This is now basically numpy.

```
In[14]: eq = numpy.array([1, 2, 3]) == [1, 2, 4]
In[15]: eq
Out[15]: array([ True,  True, False])
In[16]: eq.all()
Out[16]: False
In[17]: eq.any()
Out[17]: True
In[18]: bool(eq)
Traceback (most recent call last):
...
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()
```

I've used number instead of strings because numpy treats strings as units
instead of iterables for this kind of purpose, so you'd have to do some
extra wrapping in lists to explicitly ask for character comparisons.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/PJPTZWIUCP7GGHSYEW5TLSPGSBH45JIG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to