I believe that one of the most popular Python domains that benefit from "abusing" indexes is data analysis in the numpy/Pandas world.
I am not familiar enough with Pandas to make useful speculation on how named indexes could enhance the usage of dataframes, - maybe someone more familiar can come up with suggestions on how this syntax could be useful? On Fri, 10 Jul 2020 at 09:24, Ricky Teachey <ri...@teachey.org> wrote: > > > On Fri, Jul 10, 2020, 6:54 AM Jonathan Fine <jfine2...@gmail.com> wrote: > >> Hi All >> >> SUMMARY >> This is a longish post. It looks at the idea in general terms, and >> outlines a way to get the desired semantics (by not syntax) with Python as >> it is today. And this would be forward compatible with the new syntax, if >> provided later. >> > > This post was filled with inspiring ideas for me. Thank you. > > >> PRESENT >> I like the idea of allowing >> >>> d[1, 2, 3, a=4, b=5] >> and will explore it further. >> >> First, we can already write >> >>> f(1, 2, 3, a=4, b=5) >> but that only works for the get operation. For set the present behaviour >> is >> >>> f(1, 2, 3, a=4, b=5) = None >> SyntaxError: can't assign to function call >> and I see no good reason to change that. >> >> Going further, I'd say that allowing both >> >>> d[something] = value >> >>> value = d[something] >> is essential to the difference between f(something) and d[something]. >> Both are expressions, but only one of them can be assigned to. >> > > >> Here goes. First syntax. >> >>> value = d[K(1, 2, 3, a=4, b=5)] >> >>> d[K(1, 2, 3, a=4, b=5)] = value >> > > > My mind instantly went to the idea of using this syntax as a way write > single line mathematical function definitions: > > f[x, y] = x + y > > The example function doesn't even require the suggested K() object since > no kwargs or defaults are used. > > Of course one would need to instantiate any these single line functions > using a little bit of boilerplate up top. But this could be when you > provide the docstring: > > f = MathFunction("Simple math function") > f[x, y] = x + y > > And calling them would use a different bracket type (parentheses): > > >>> f(1,2) > 3 > > ...but these are surmountable hurdles. > >> _______________________________________________ > 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/QKDZ4Y6KBIVEFJ34ITLZHUT4IPE3QBBQ/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ 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/VUY3NPQ2FBAJ4L6LAMR7CU757IQRZFCN/ Code of Conduct: http://python.org/psf/codeofconduct/