Frage

I am trying to understand syntax of

attributeMap[tuple[0]] = tuple[1]

from

I have Python code for detecting input parameter - How to do similar in Powershell

It doesn't look correct because the brackets are uneven, but the program is interpreted without error. On the other hand if I change it to

attributeMap[tuple[0] = tuple[1]]

I get the error

File "lookup.py", line 15
attributeMap[tuple[0] = tuple[1]]
War es hilfreich?

Lösung

The brackets are not "uneven" at all:

 attributeMap[tuple[0]] = tuple[1]

We have three expressions here:

 tuple[0] # first element of tuple
 tuple[1] # second element of tuple
 attributeMap[tuple[0]] # value in attributeMap which has the key matching first element of tuple

As you can see, the third expression makes use of the first, and at the end all we do is assign the second to the third. The brackets are in the right places.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top