python dictionary key pointing to value of another key in the same dictionary The 2019 Stack Overflow Developer Survey Results Are InHow to clone or copy a list?Reference a dictionary within itselfHow do I sort a list of dictionaries by a value of the dictionary?Hidden features of PythonHow to return multiple values from a function?How do I sort a dictionary by value?Add new keys to a dictionary?Check if a given key already exists in a dictionaryCreate a dictionary with list comprehension in PythonHow to remove a key from a Python dictionary?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?I have a nested list which contain key, value in every row. how to put this list data into dataframe
Is Cinnamon a desktop environment or a window manager? (Or both?)
What do these terms in Caesar's Gallic Wars mean?
"as much details as you can remember"
Correct punctuation for showing a character's confusion
What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?
Accepted by European university, rejected by all American ones I applied to? Possible reasons?
Does HR tell a hiring manager about salary negotiations?
What is the meaning of Triage in Cybersec world?
Does adding complexity mean a more secure cipher?
Keeping a retro style to sci-fi spaceships?
Can withdrawing asylum be illegal?
Why couldn't they take pictures of a closer black hole?
Why does the nucleus not repel itself?
Are there any other methods to apply to solving simultaneous equations?
Kerning for subscripts of sigma?
How do you keep chess fun when your opponent constantly beats you?
Can we generate random numbers using irrational numbers like π and e?
How to support a colleague who finds meetings extremely tiring?
What is preventing me from simply constructing a hash that's lower than the current target?
Why isn't the circumferential light around the M87 black hole's event horizon symmetric?
Cooking pasta in a water boiler
Ubuntu Server install with full GUI
Why can't devices on different VLANs, but on the same subnet, communicate?
Short story: man watches girlfriend's spaceship entering a 'black hole' (?) forever
python dictionary key pointing to value of another key in the same dictionary
The 2019 Stack Overflow Developer Survey Results Are InHow to clone or copy a list?Reference a dictionary within itselfHow do I sort a list of dictionaries by a value of the dictionary?Hidden features of PythonHow to return multiple values from a function?How do I sort a dictionary by value?Add new keys to a dictionary?Check if a given key already exists in a dictionaryCreate a dictionary with list comprehension in PythonHow to remove a key from a Python dictionary?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?I have a nested list which contain key, value in every row. how to put this list data into dataframe
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a python dictionary that has the below format
data = 'key1': 'value1',
'key2': 'value2',
'key3': 'value3'
I want this key3
value to point to the value of key1
.
what i tried so far is 'key3': key1['value1']
or 'key3': data['key1']
and both of them seem to be invalid syntaxes.
python
add a comment |
I have a python dictionary that has the below format
data = 'key1': 'value1',
'key2': 'value2',
'key3': 'value3'
I want this key3
value to point to the value of key1
.
what i tried so far is 'key3': key1['value1']
or 'key3': data['key1']
and both of them seem to be invalid syntaxes.
python
1
You can't reference the dictionary from within itself while constructing it as it doesn't exist as an object yet...
– Jon Clements♦
Mar 22 at 5:05
Also - when you say I want this key3 value to point to the value of key1 - did you expect when you changed the value ofkey1
the accessingkey3
would give you the updated value or the old value?
– Jon Clements♦
Mar 22 at 5:07
@JonClements i expect the value ofkey3
to change whenkey1
changes
– prex
Mar 22 at 5:10
Possible duplication :stackoverflow.com/questions/38254969/…
– Sean_Syue
Mar 22 at 5:10
Also - you'd need to be remarkably wary of cyclic references... if key3 should retrieve the value of key1's value, but accessing key1 tries to return the value of key3...
– Jon Clements♦
Mar 22 at 5:19
add a comment |
I have a python dictionary that has the below format
data = 'key1': 'value1',
'key2': 'value2',
'key3': 'value3'
I want this key3
value to point to the value of key1
.
what i tried so far is 'key3': key1['value1']
or 'key3': data['key1']
and both of them seem to be invalid syntaxes.
python
I have a python dictionary that has the below format
data = 'key1': 'value1',
'key2': 'value2',
'key3': 'value3'
I want this key3
value to point to the value of key1
.
what i tried so far is 'key3': key1['value1']
or 'key3': data['key1']
and both of them seem to be invalid syntaxes.
python
python
asked Mar 22 at 5:03
prexprex
135213
135213
1
You can't reference the dictionary from within itself while constructing it as it doesn't exist as an object yet...
– Jon Clements♦
Mar 22 at 5:05
Also - when you say I want this key3 value to point to the value of key1 - did you expect when you changed the value ofkey1
the accessingkey3
would give you the updated value or the old value?
– Jon Clements♦
Mar 22 at 5:07
@JonClements i expect the value ofkey3
to change whenkey1
changes
– prex
Mar 22 at 5:10
Possible duplication :stackoverflow.com/questions/38254969/…
– Sean_Syue
Mar 22 at 5:10
Also - you'd need to be remarkably wary of cyclic references... if key3 should retrieve the value of key1's value, but accessing key1 tries to return the value of key3...
– Jon Clements♦
Mar 22 at 5:19
add a comment |
1
You can't reference the dictionary from within itself while constructing it as it doesn't exist as an object yet...
– Jon Clements♦
Mar 22 at 5:05
Also - when you say I want this key3 value to point to the value of key1 - did you expect when you changed the value ofkey1
the accessingkey3
would give you the updated value or the old value?
– Jon Clements♦
Mar 22 at 5:07
@JonClements i expect the value ofkey3
to change whenkey1
changes
– prex
Mar 22 at 5:10
Possible duplication :stackoverflow.com/questions/38254969/…
– Sean_Syue
Mar 22 at 5:10
Also - you'd need to be remarkably wary of cyclic references... if key3 should retrieve the value of key1's value, but accessing key1 tries to return the value of key3...
– Jon Clements♦
Mar 22 at 5:19
1
1
You can't reference the dictionary from within itself while constructing it as it doesn't exist as an object yet...
– Jon Clements♦
Mar 22 at 5:05
You can't reference the dictionary from within itself while constructing it as it doesn't exist as an object yet...
– Jon Clements♦
Mar 22 at 5:05
Also - when you say I want this key3 value to point to the value of key1 - did you expect when you changed the value of
key1
the accessing key3
would give you the updated value or the old value?– Jon Clements♦
Mar 22 at 5:07
Also - when you say I want this key3 value to point to the value of key1 - did you expect when you changed the value of
key1
the accessing key3
would give you the updated value or the old value?– Jon Clements♦
Mar 22 at 5:07
@JonClements i expect the value of
key3
to change when key1
changes– prex
Mar 22 at 5:10
@JonClements i expect the value of
key3
to change when key1
changes– prex
Mar 22 at 5:10
Possible duplication :stackoverflow.com/questions/38254969/…
– Sean_Syue
Mar 22 at 5:10
Possible duplication :stackoverflow.com/questions/38254969/…
– Sean_Syue
Mar 22 at 5:10
Also - you'd need to be remarkably wary of cyclic references... if key3 should retrieve the value of key1's value, but accessing key1 tries to return the value of key3...
– Jon Clements♦
Mar 22 at 5:19
Also - you'd need to be remarkably wary of cyclic references... if key3 should retrieve the value of key1's value, but accessing key1 tries to return the value of key3...
– Jon Clements♦
Mar 22 at 5:19
add a comment |
2 Answers
2
active
oldest
votes
Python doesn't support pointers like C/C++ does, but you could use lists to serve as references. To access the value, you'd index into the first element of the list.
data =
'key1': ['value1']
data['key3'] = data['key1'] # copy the list by reference
print(f"Old: data['key3'][0], data['key3'][0] == data['key1'][0]")
data['key1'][0] = 'new-value' # this will modify the value from data['key3'] as well
print(f"New: data['key3'][0], data['key3'][0] == data['key1'][0]")
Output:
Old: value1, True
New: new-value, True
Note that, this assumes that you're fully aware of which values act as "pointers" and which ones don't.
For example,
data =
'key1': ['pointer-list'], # should act as a "pointer"
'key2': ['normal', 'list'] # should act as a normal list
data['key3'] = data['key1'] # copy list by reference
data['key1'][0] = 'new-value' # propogate new value to other references
data['key4'] = data['key2'] # oops – copy list by reference
data['key2'][0] = 'new-value' # oops – data['key2'] should act as a normal list but
# the new value is propogated to data['key4'] as well
To deal with this issue, clone or copy the list instead.
import copy
data['key4'] = copy.copy(data['key2'])
# data['key4'] = copy.deepcopy(data['key2']) # if the value contains nested lists
# data['key4'] = data['key2'].copy() # another way
You have to know to check if it's a list though... and then if lists are valid values, then...
– Jon Clements♦
Mar 22 at 5:14
@JonClements As in... before the value is set (e.g. checking beforedata['key1'][0] = 'new_value'
)? I don't quite understand the other part, can you elaborate a bit more? :D
– TrebledJ
Mar 22 at 5:16
1
A dynamic work around would be a custom dict-like object that only contains values that references another dict, and that dict contains the real values, eg:'key1': 1, 'key2': 2, 'key3': 1
and that proxies all operations to the real dict such as1: 'value1', 2: 'value2'
...
– Jon Clements♦
Mar 22 at 5:38
1
I suppose another consideration is what should the behaviour ofdel data['key1']
have... shouldkey3
be keeping that object alive or since the value of what it held is gone, shouldkey3
now not have a value? :)
– Jon Clements♦
Mar 22 at 5:42
1
I suppose what you could do here is make everything a list and always make sure to access the first element... that way the ambiguity is gone.
– Jon Clements♦
Mar 22 at 5:52
|
show 3 more comments
Try this
data = 'key1': 'value1', 'key2': 'value2', 'key3': 'value3'
data['key3'] = data['key1']
print(data)
Prints out:
'key3': 'value1', 'key2': 'value2', 'key1': 'value1'
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293200%2fpython-dictionary-key-pointing-to-value-of-another-key-in-the-same-dictionary%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Python doesn't support pointers like C/C++ does, but you could use lists to serve as references. To access the value, you'd index into the first element of the list.
data =
'key1': ['value1']
data['key3'] = data['key1'] # copy the list by reference
print(f"Old: data['key3'][0], data['key3'][0] == data['key1'][0]")
data['key1'][0] = 'new-value' # this will modify the value from data['key3'] as well
print(f"New: data['key3'][0], data['key3'][0] == data['key1'][0]")
Output:
Old: value1, True
New: new-value, True
Note that, this assumes that you're fully aware of which values act as "pointers" and which ones don't.
For example,
data =
'key1': ['pointer-list'], # should act as a "pointer"
'key2': ['normal', 'list'] # should act as a normal list
data['key3'] = data['key1'] # copy list by reference
data['key1'][0] = 'new-value' # propogate new value to other references
data['key4'] = data['key2'] # oops – copy list by reference
data['key2'][0] = 'new-value' # oops – data['key2'] should act as a normal list but
# the new value is propogated to data['key4'] as well
To deal with this issue, clone or copy the list instead.
import copy
data['key4'] = copy.copy(data['key2'])
# data['key4'] = copy.deepcopy(data['key2']) # if the value contains nested lists
# data['key4'] = data['key2'].copy() # another way
You have to know to check if it's a list though... and then if lists are valid values, then...
– Jon Clements♦
Mar 22 at 5:14
@JonClements As in... before the value is set (e.g. checking beforedata['key1'][0] = 'new_value'
)? I don't quite understand the other part, can you elaborate a bit more? :D
– TrebledJ
Mar 22 at 5:16
1
A dynamic work around would be a custom dict-like object that only contains values that references another dict, and that dict contains the real values, eg:'key1': 1, 'key2': 2, 'key3': 1
and that proxies all operations to the real dict such as1: 'value1', 2: 'value2'
...
– Jon Clements♦
Mar 22 at 5:38
1
I suppose another consideration is what should the behaviour ofdel data['key1']
have... shouldkey3
be keeping that object alive or since the value of what it held is gone, shouldkey3
now not have a value? :)
– Jon Clements♦
Mar 22 at 5:42
1
I suppose what you could do here is make everything a list and always make sure to access the first element... that way the ambiguity is gone.
– Jon Clements♦
Mar 22 at 5:52
|
show 3 more comments
Python doesn't support pointers like C/C++ does, but you could use lists to serve as references. To access the value, you'd index into the first element of the list.
data =
'key1': ['value1']
data['key3'] = data['key1'] # copy the list by reference
print(f"Old: data['key3'][0], data['key3'][0] == data['key1'][0]")
data['key1'][0] = 'new-value' # this will modify the value from data['key3'] as well
print(f"New: data['key3'][0], data['key3'][0] == data['key1'][0]")
Output:
Old: value1, True
New: new-value, True
Note that, this assumes that you're fully aware of which values act as "pointers" and which ones don't.
For example,
data =
'key1': ['pointer-list'], # should act as a "pointer"
'key2': ['normal', 'list'] # should act as a normal list
data['key3'] = data['key1'] # copy list by reference
data['key1'][0] = 'new-value' # propogate new value to other references
data['key4'] = data['key2'] # oops – copy list by reference
data['key2'][0] = 'new-value' # oops – data['key2'] should act as a normal list but
# the new value is propogated to data['key4'] as well
To deal with this issue, clone or copy the list instead.
import copy
data['key4'] = copy.copy(data['key2'])
# data['key4'] = copy.deepcopy(data['key2']) # if the value contains nested lists
# data['key4'] = data['key2'].copy() # another way
You have to know to check if it's a list though... and then if lists are valid values, then...
– Jon Clements♦
Mar 22 at 5:14
@JonClements As in... before the value is set (e.g. checking beforedata['key1'][0] = 'new_value'
)? I don't quite understand the other part, can you elaborate a bit more? :D
– TrebledJ
Mar 22 at 5:16
1
A dynamic work around would be a custom dict-like object that only contains values that references another dict, and that dict contains the real values, eg:'key1': 1, 'key2': 2, 'key3': 1
and that proxies all operations to the real dict such as1: 'value1', 2: 'value2'
...
– Jon Clements♦
Mar 22 at 5:38
1
I suppose another consideration is what should the behaviour ofdel data['key1']
have... shouldkey3
be keeping that object alive or since the value of what it held is gone, shouldkey3
now not have a value? :)
– Jon Clements♦
Mar 22 at 5:42
1
I suppose what you could do here is make everything a list and always make sure to access the first element... that way the ambiguity is gone.
– Jon Clements♦
Mar 22 at 5:52
|
show 3 more comments
Python doesn't support pointers like C/C++ does, but you could use lists to serve as references. To access the value, you'd index into the first element of the list.
data =
'key1': ['value1']
data['key3'] = data['key1'] # copy the list by reference
print(f"Old: data['key3'][0], data['key3'][0] == data['key1'][0]")
data['key1'][0] = 'new-value' # this will modify the value from data['key3'] as well
print(f"New: data['key3'][0], data['key3'][0] == data['key1'][0]")
Output:
Old: value1, True
New: new-value, True
Note that, this assumes that you're fully aware of which values act as "pointers" and which ones don't.
For example,
data =
'key1': ['pointer-list'], # should act as a "pointer"
'key2': ['normal', 'list'] # should act as a normal list
data['key3'] = data['key1'] # copy list by reference
data['key1'][0] = 'new-value' # propogate new value to other references
data['key4'] = data['key2'] # oops – copy list by reference
data['key2'][0] = 'new-value' # oops – data['key2'] should act as a normal list but
# the new value is propogated to data['key4'] as well
To deal with this issue, clone or copy the list instead.
import copy
data['key4'] = copy.copy(data['key2'])
# data['key4'] = copy.deepcopy(data['key2']) # if the value contains nested lists
# data['key4'] = data['key2'].copy() # another way
Python doesn't support pointers like C/C++ does, but you could use lists to serve as references. To access the value, you'd index into the first element of the list.
data =
'key1': ['value1']
data['key3'] = data['key1'] # copy the list by reference
print(f"Old: data['key3'][0], data['key3'][0] == data['key1'][0]")
data['key1'][0] = 'new-value' # this will modify the value from data['key3'] as well
print(f"New: data['key3'][0], data['key3'][0] == data['key1'][0]")
Output:
Old: value1, True
New: new-value, True
Note that, this assumes that you're fully aware of which values act as "pointers" and which ones don't.
For example,
data =
'key1': ['pointer-list'], # should act as a "pointer"
'key2': ['normal', 'list'] # should act as a normal list
data['key3'] = data['key1'] # copy list by reference
data['key1'][0] = 'new-value' # propogate new value to other references
data['key4'] = data['key2'] # oops – copy list by reference
data['key2'][0] = 'new-value' # oops – data['key2'] should act as a normal list but
# the new value is propogated to data['key4'] as well
To deal with this issue, clone or copy the list instead.
import copy
data['key4'] = copy.copy(data['key2'])
# data['key4'] = copy.deepcopy(data['key2']) # if the value contains nested lists
# data['key4'] = data['key2'].copy() # another way
edited Mar 22 at 5:39
answered Mar 22 at 5:09
TrebledJTrebledJ
3,80421329
3,80421329
You have to know to check if it's a list though... and then if lists are valid values, then...
– Jon Clements♦
Mar 22 at 5:14
@JonClements As in... before the value is set (e.g. checking beforedata['key1'][0] = 'new_value'
)? I don't quite understand the other part, can you elaborate a bit more? :D
– TrebledJ
Mar 22 at 5:16
1
A dynamic work around would be a custom dict-like object that only contains values that references another dict, and that dict contains the real values, eg:'key1': 1, 'key2': 2, 'key3': 1
and that proxies all operations to the real dict such as1: 'value1', 2: 'value2'
...
– Jon Clements♦
Mar 22 at 5:38
1
I suppose another consideration is what should the behaviour ofdel data['key1']
have... shouldkey3
be keeping that object alive or since the value of what it held is gone, shouldkey3
now not have a value? :)
– Jon Clements♦
Mar 22 at 5:42
1
I suppose what you could do here is make everything a list and always make sure to access the first element... that way the ambiguity is gone.
– Jon Clements♦
Mar 22 at 5:52
|
show 3 more comments
You have to know to check if it's a list though... and then if lists are valid values, then...
– Jon Clements♦
Mar 22 at 5:14
@JonClements As in... before the value is set (e.g. checking beforedata['key1'][0] = 'new_value'
)? I don't quite understand the other part, can you elaborate a bit more? :D
– TrebledJ
Mar 22 at 5:16
1
A dynamic work around would be a custom dict-like object that only contains values that references another dict, and that dict contains the real values, eg:'key1': 1, 'key2': 2, 'key3': 1
and that proxies all operations to the real dict such as1: 'value1', 2: 'value2'
...
– Jon Clements♦
Mar 22 at 5:38
1
I suppose another consideration is what should the behaviour ofdel data['key1']
have... shouldkey3
be keeping that object alive or since the value of what it held is gone, shouldkey3
now not have a value? :)
– Jon Clements♦
Mar 22 at 5:42
1
I suppose what you could do here is make everything a list and always make sure to access the first element... that way the ambiguity is gone.
– Jon Clements♦
Mar 22 at 5:52
You have to know to check if it's a list though... and then if lists are valid values, then...
– Jon Clements♦
Mar 22 at 5:14
You have to know to check if it's a list though... and then if lists are valid values, then...
– Jon Clements♦
Mar 22 at 5:14
@JonClements As in... before the value is set (e.g. checking before
data['key1'][0] = 'new_value'
)? I don't quite understand the other part, can you elaborate a bit more? :D– TrebledJ
Mar 22 at 5:16
@JonClements As in... before the value is set (e.g. checking before
data['key1'][0] = 'new_value'
)? I don't quite understand the other part, can you elaborate a bit more? :D– TrebledJ
Mar 22 at 5:16
1
1
A dynamic work around would be a custom dict-like object that only contains values that references another dict, and that dict contains the real values, eg:
'key1': 1, 'key2': 2, 'key3': 1
and that proxies all operations to the real dict such as 1: 'value1', 2: 'value2'
...– Jon Clements♦
Mar 22 at 5:38
A dynamic work around would be a custom dict-like object that only contains values that references another dict, and that dict contains the real values, eg:
'key1': 1, 'key2': 2, 'key3': 1
and that proxies all operations to the real dict such as 1: 'value1', 2: 'value2'
...– Jon Clements♦
Mar 22 at 5:38
1
1
I suppose another consideration is what should the behaviour of
del data['key1']
have... should key3
be keeping that object alive or since the value of what it held is gone, should key3
now not have a value? :)– Jon Clements♦
Mar 22 at 5:42
I suppose another consideration is what should the behaviour of
del data['key1']
have... should key3
be keeping that object alive or since the value of what it held is gone, should key3
now not have a value? :)– Jon Clements♦
Mar 22 at 5:42
1
1
I suppose what you could do here is make everything a list and always make sure to access the first element... that way the ambiguity is gone.
– Jon Clements♦
Mar 22 at 5:52
I suppose what you could do here is make everything a list and always make sure to access the first element... that way the ambiguity is gone.
– Jon Clements♦
Mar 22 at 5:52
|
show 3 more comments
Try this
data = 'key1': 'value1', 'key2': 'value2', 'key3': 'value3'
data['key3'] = data['key1']
print(data)
Prints out:
'key3': 'value1', 'key2': 'value2', 'key1': 'value1'
add a comment |
Try this
data = 'key1': 'value1', 'key2': 'value2', 'key3': 'value3'
data['key3'] = data['key1']
print(data)
Prints out:
'key3': 'value1', 'key2': 'value2', 'key1': 'value1'
add a comment |
Try this
data = 'key1': 'value1', 'key2': 'value2', 'key3': 'value3'
data['key3'] = data['key1']
print(data)
Prints out:
'key3': 'value1', 'key2': 'value2', 'key1': 'value1'
Try this
data = 'key1': 'value1', 'key2': 'value2', 'key3': 'value3'
data['key3'] = data['key1']
print(data)
Prints out:
'key3': 'value1', 'key2': 'value2', 'key1': 'value1'
answered Mar 22 at 5:05
LeonidLeonid
4392715
4392715
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293200%2fpython-dictionary-key-pointing-to-value-of-another-key-in-the-same-dictionary%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You can't reference the dictionary from within itself while constructing it as it doesn't exist as an object yet...
– Jon Clements♦
Mar 22 at 5:05
Also - when you say I want this key3 value to point to the value of key1 - did you expect when you changed the value of
key1
the accessingkey3
would give you the updated value or the old value?– Jon Clements♦
Mar 22 at 5:07
@JonClements i expect the value of
key3
to change whenkey1
changes– prex
Mar 22 at 5:10
Possible duplication :stackoverflow.com/questions/38254969/…
– Sean_Syue
Mar 22 at 5:10
Also - you'd need to be remarkably wary of cyclic references... if key3 should retrieve the value of key1's value, but accessing key1 tries to return the value of key3...
– Jon Clements♦
Mar 22 at 5:19