Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7921441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:35:06+00:00 2026-06-03T16:35:06+00:00

Sorry to ask a silly question, but I can’t find a complete answer. With

  • 0

Sorry to ask a silly question, but I can’t find a complete answer.

With the following:

a_dict = {"A":0, "B":0}
def GetElementRef(index):
    return a_dict[index]
would_like_to_modify = GetElementRef("A")
would_like_to_modify = 2

This results in would_like_to_modify being given the value of 2, while a_dict remains unchanged.

AFAIK, any assignment based operation on would_like_to_modify just reseats the reference. Is there any way to modify the original dictionary element in this indirect way?

I am aware of a few other ways I can implement this by directly referring to the dictionary, but I’m curious if this can somehow be done.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:35:09+00:00Added an answer on June 3, 2026 at 4:35 pm

    For the code in the question, the answer is “no”, because the values in the dictionary are numbers, and numbers are immutable. On the other hand, if the values were mutable, they can indeed be changed. For example:

    a_dict = {"A":[0], "B":[0]}
    
    def GetElementRef(index):
        return a_dict[index]
    
    would_like_to_modify = GetElementRef("A")
    print would_like_to_modify
    > [0]
    
    would_like_to_modify[0] = 2
    print would_like_to_modify
    > [2]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry to ask a question like that but I can't found a good answer
I am sorry to ask this trivial question but I could not find a
I'm sorry to ask such a basic question but I could not find a
Sorry if I ask silly question, but so far had no luck in figuring
Sorry to ask such a noob question, but the NDK documentation is wrong (r7b):
Sorry to ask this question again but I tried several solutions on stackoverflow and
I am very sorry to ask such a basic question but I am new
I'm sorry to ask a question but I am useless when it comes to
Sorry for being the 100000th person to ask the same question. But I guess
I'm sorry to ask such a simple question, but it's a specific question I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.