On Fri, Jul 04, 2014 at 08:20:18PM +0200, Oleg Broytman wrote:
On Fri, Jul 04, 2014 at 08:10:51PM +0200, Stefano Borini
wrote: C1. a[Z=3] -> idx = {"Z": 3} C2. a[Z=3, R=4] -> idx = {"Z"=3, "R"=4}
Huh? Shouldn't it be C2. a[Z=3, R=4] -> idx = {"Z": 3, "R": 4}
yes. typo. already fixed in the PEP
Cons: - degeneracy of a[{"Z": 3, "R": 4}] with a[Z=3, R=4], but the same degeneracy exists for a[(2,3)] and a[2,3].
There is no degeneration in the second case. Tuples are created by commas, not parentheses (except for an empty tuple), hence (2,3) and 2,3 are simply the same thing.
We discussed this point above in the thread, and you are of course right in saying so, yet it stresses the fact that no matter what you pass inside those square brackets, they always end up funneled inside a single object, which happens to be a tuple that you just created
While Z=3, R=4 is far from being the same as {"Z": 3, "R": 4}.
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.