Created
November 3, 2016 14:01
-
-
Save drj11/287c9f565d387cbfb96f69265c6f41de to your computer and use it in GitHub Desktop.
structure sharing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a=[1] | |
b=['b'] | |
c=['c'] | |
b.append(a) | |
c.append(a) | |
print(b) | |
print(c) | |
b[1].append('xyz') | |
print(b) | |
print(c) |
I think if you drew a diagram it would become clear that: you don't really use that model above; or, it's terrible.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Numbers are line numbers above
(remember python values are all objects, so being more specific below)
[1]
, and stick the label a onto that value. Below refers to this specific object asA
. (Remember [1] is a representation, not the value)['b']
and stick the label b onto that value. Below refers to this specific object asB
['c']
and stick the label c onto that value. Below refers to this specific object asC
A
) and use it as an argument to a function call. Find the value that "b" refers to it (B
), and find the value that the label "append" is stuck onto (append func
). Treat that value (append func
) as a function and pass it the two specific values (B
) and (A
) we found earlier.append_func
takes the valueA
and appends it to the objectB
. (Current representation. of objectB
:['b', [1] ]
) Note, that this is because the label b[0] refers to the value"b"
and the label b[1] is stuck onto the valueA
A
) and use it as an argument to a function call. Find the value that "c" refers to it (C
), and find the value that the label "append" is stuck onto (append func
). Treat that value (append func
) as a function and pass it the two specific values (C
) and (A
) we found earlier.append_func
takes the valueA
and appends it to the objectB
. (Current representation. of objectC
:['c', [1] ]
) Note, that this is because the label c[0] refers to the value"c"
and the label c[1] is stuck onto the valueA
['b', [1] ]
['c', [1] ]
b[1]
is stuck on - which is the valueA
- and append the value"xyz"
to the end ofA
."b"
and b[1] is stuck onA
, this displays:['b', [1,
"xyz"] ]
"c"
and c[1] is stuck onA
, this displays:['c', [1,
"xyz"] ]
Remember "=" means "stick the label on". Therefore as odd as it sounds, b[0] is a label, as is b[1], as is c[0], c[1], etc.
It just happens that the variable
b
andc
also understand how to remember what these labels what values are stuck to.