Kevin Mills suggested:
> > > d = {1: {2: {3: 4}}}
> > > keys= 1,2,3
> > > print(d[*keys])
> > > d[*keys] = None
> > > print(d)
> > >
> > > Hopefully it's clear from that example what I'm suggesting.
MRAB replied:
> > Would that be equivalent to d[keys[0], keys[1], keys[2]]?
> >
> > If so, it would be equivalent to something that's already legal,
> > namely, a subscript that's a tuple.
and Kevin responded:
> No, definitely not. d[1,2,3] and d[1][2][3] are not the same thing.
> The latter is what I am talking about.
Ah, I read it the same as MRAB did.
I think it would be *very* unfortunate if `*args` had a different
meaning in subscripts from the meaning elsewhere:
keys = (1, 2, 3)
f(*keys) # like f(1, 2, 3)
d[*keys] # like d[1][2][3]
I think it might be better to start with a *function* that chains
subscript calls, and perhaps put it in the operator module with
itemgetter and attrgetter.
# Untested.
def chained_item(items, obj):
for key in items:
obj = obj[key]
return obj
--
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/OZ3BSHDYNKBWOMLIN5VSIBS7CU3ONT3H/
Code of Conduct: http://python.org/psf/codeofconduct/