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;








0















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.










share|improve this question

















  • 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 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











  • 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

















0















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.










share|improve this question

















  • 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 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











  • 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













0












0








0








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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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











  • 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





    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











  • @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











  • 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












2 Answers
2






active

oldest

votes


















1














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





share|improve this answer

























  • 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







  • 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






  • 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






  • 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



















0














Try this



data = 'key1': 'value1', 'key2': 'value2', 'key3': 'value3' 

data['key3'] = data['key1']

print(data)


Prints out:



'key3': 'value1', 'key2': 'value2', 'key1': 'value1'





share|improve this answer























    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
    );



    );













    draft saved

    draft discarded


















    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









    1














    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





    share|improve this answer

























    • 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







    • 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






    • 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






    • 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
















    1














    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





    share|improve this answer

























    • 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







    • 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






    • 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






    • 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














    1












    1








    1







    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





    share|improve this answer















    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






    share|improve this answer














    share|improve this answer



    share|improve this answer








    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 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





      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





      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





      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











    • @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





      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





      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





      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














    0














    Try this



    data = 'key1': 'value1', 'key2': 'value2', 'key3': 'value3' 

    data['key3'] = data['key1']

    print(data)


    Prints out:



    'key3': 'value1', 'key2': 'value2', 'key1': 'value1'





    share|improve this answer



























      0














      Try this



      data = 'key1': 'value1', 'key2': 'value2', 'key3': 'value3' 

      data['key3'] = data['key1']

      print(data)


      Prints out:



      'key3': 'value1', 'key2': 'value2', 'key1': 'value1'





      share|improve this answer

























        0












        0








        0







        Try this



        data = 'key1': 'value1', 'key2': 'value2', 'key3': 'value3' 

        data['key3'] = data['key1']

        print(data)


        Prints out:



        'key3': 'value1', 'key2': 'value2', 'key1': 'value1'





        share|improve this answer













        Try this



        data = 'key1': 'value1', 'key2': 'value2', 'key3': 'value3' 

        data['key3'] = data['key1']

        print(data)


        Prints out:



        'key3': 'value1', 'key2': 'value2', 'key1': 'value1'






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 5:05









        LeonidLeonid

        4392715




        4392715



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현