On Fri, 8 May 2020 23:10:05 +1000
Steven D'Aprano <st...@pearwood.info> wrote:

> On Thu, May 07, 2020 at 03:43:23PM +0200, Dominik Vilsmeier wrote:

> > How common is it to compare two objects where you cannot determine
> > whether one or the other is a tuple or a list already from the
> > surrounding context? In the end these objects must come from somewhere
> > and usually functions declare either list or tuple as their return type.

> Never, because we can always determine whether something is a list or 
> tuple by inspecting it with type() or isinstance(). But that's missing 
> the point! I don't care and don't want to know if it is a tuple or 
> list, I only care if it quacks like a sequence of some kind.

> The use-case for this is for when you want to compare elements without 
> regard to the type of the container they are in. This is a duck-typing 
> sequence element-by-element equality test.

To rephrase Dominik's question slighly, how often do you have a block of
code with two sequences of unknown origin?  Sure, I can *hypothisize*
f(x, y) where x and y don't have to be anything more specific than
sequences.  But unless I'm actually writing .EQ., there's some code
inside f that builds x or y, or calls some other function to obtain x or
y, and then I know at least one of the types.

You often ask for real world code that would be simpler or easier to
read or maintain if such-and-such feature existed.  The OP never posted
any such thing; do you have any specific code in mind?

> If you have ever written something like any of these:
> 
>     list(a) == list(b)
>     tuple(a) == b
>     ''.join(chars) == mystring
>     all(x==y for x,y in zip(a, b))
> 
> then this proposed operator might be just what you need.

Ever?  Maybe.  Do I need help from a new operator or the standard
library when it comes up?  No, not really.  And except for that
join/mystring example, I find all of thse examples incredibly obvious
and simple to read (although looking up a new function or operator isn't
onerous, and I often learn things when that happens).

-- 
“Atoms are not things.” – Werner Heisenberg
Dan Sommers, http://www.tombstonezero.net/dan
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/PU2GE3BVZOAAW7DRFWBRYUHHX6RII3MP/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to