This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: New `both()` operator for matching multiple variables to one
Type: enhancement Stage: resolved
Components: Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: billyeatcookies, eric.smith, steven.daprano
Priority: normal Keywords:

Created on 2021-12-23 14:22 by billyeatcookies, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg409091 - (view) Author: Billy (billyeatcookies) Date: 2021-12-23 14:22
A new `both()` operator for matching multiple variables to one at the same time.

Currently,
```py
if a == 1 and b == 1:
    ...
```

With a `both()` operator, it can be done as follows (concept):
```py
if both(a, b) == 1:
    ...
```

Why? 
-> With the increasing number of variables, it may be hard to compare each of them at once, hence this operator can help a lot in such situations. 
Of course, using lists appropriately can solve this issue easily, but a general-direct method for achieving this would be a lot helpful. This also makes the code more simplistic and easily readable and understandable.



*Sorry for the bad formatting if markdown is not supported for this comment section, I couldn't find it mentioned anywhere in the python developer's guide. Hence I'm assuming it is supported since it's a common and highly needed feature nowadays.
msg409092 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-12-23 14:28
I think this is a rarely needed operation. I looked through a few tens of thousand lines of my code and couldn't find anywhere it would be used.

Plus, you could write it yourself, so I don't see the advantage of it being part of the language or standard library.
msg409096 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-12-23 15:35
Just use

    if a == b == 1:

Comparisons can be chained arbitrarily.

https://docs.python.org/3/reference/expressions.html#comparisons
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90322
2021-12-23 15:35:30steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg409096

resolution: rejected
stage: resolved
2021-12-23 14:28:33eric.smithsetnosy: + eric.smith
messages: + msg409092
2021-12-23 14:22:03billyeatcookiescreate