I believe this is useful since this syntax is developed in some libraries as an internal DSL. At least I have seen it in pandas, a library handling tables.

    df[(df['a'] < df['b']) & (df['b'] < df['c'])]


    df[df['b'].isin(df['a']) & (df['c'] < df['d'])]

More examples in {[pandas-doc-url]/user_guide/indexing.html}.

On 13/08/2021 20:18, Matsuoka Takuo wrote:
Dear Developers,

Given a subscriptable object s, the intended rule for the notation for
getting an item of s seems that, for any expression {e}, such as
"x, ",
(i.e., s[x, ] if {e} is "x, ") means the same as
(i.e., s[(x, )] in the considered case), namely, should be evaluated
as s.__getitem__(({e})) (or s.__class_getitem__(({e})) when that
applies). If this is the rule, then it looks simple and hence
friendly to the user. However, there are at least two exceptions:

(1) The case where {e} is the empty expression "":
The expression
raises SyntaxError instead of being evaluated in the same way as
s[()] is.

(2) The case where {e} contains "*" for unpacking:
An expression containing the unpacking notation, such as
  s[*iterable, ]
raises SyntaxError instead of being evaluated in the same way as
s[(*iterable, )] in this example, is.

Are these (and other if any) exceptions justified? If not, I propose
having the described rule to have full effect if that would simplify
the syntax. This would affect currently working codes which rely on
SyntaxError raised in either of the described ways (through eval, exec
or import??). I wonder if reliance on SyntaxError in these cases
should be supported in all future versions of Python.

Best regards,
Takuo Matsuoka
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/V2WFMNVJLUBXVQFPNHH4TJNRYNPK2BKJ/
Code of Conduct: http://python.org/psf/codeofconduct/