[Python-ideas] PEP pre-draft: Support for indexing with keyword arguments

Stefano Borini stefano.borini at ferrara.linux.it
Fri Jul 4 20:40:56 CEST 2014


On Fri, Jul 04, 2014 at 08:34:24PM +0200, Stefano Borini wrote:
> but dict(Z=3, R=4) is the same as {"Z": 3, "R": 4}. 
> this is exactly like tuple((2,3)) is the same as (2,3)
> See the similarity? the square brackets "call a constructor"
> on its content. This constructor is tuple if entries are not
> key=values (except for the single index case, of course), 
> and dict if entries are key=values.

On this regard, one can of course do 

idx=(2,3)
print(a[idx])

idx={"x":2, "y":3}
print(a[idx])

the above syntax is already legal today, and calls back to a comment from
a previous post. keywords would just be a shorthand for it.





More information about the Python-ideas mailing list