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 6864171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:52:41+00:00 2026-05-27T02:52:41+00:00

I am a beginner in Python. The dynamic programming solution to the coin change

  • 0

I am a beginner in Python. The dynamic programming solution to the coin change problem requires an initialized table that basically could, for example, look like this:

[
[1,0,0,0],
[1,0,0,0],
[1,0,0,0]
]

Which table I specified this way:

table=[[1]+[0]*3]*3

Now, if I write

table[1][2]=1
for x in table: print x

I get a print of:

[1, 0, 2, 0]
[1, 0, 2, 0]
[1, 0, 2, 0]

And I have no damn clue why the whole column gets changed instead of the specified number.

  • 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-05-27T02:52:41+00:00Added an answer on May 27, 2026 at 2:52 am

    The error is in the code you didn’t show. Presumably, you initialised your list like

    a = [1, 0, 0, 0]
    table = [a, a, a]
    

    or

    table = [[1, 0, 0, 0]] * 3
    

    or something equivalent, which leads to a list containing three times the same list object. If you modify this single object, it changes everywhere it is referenced, because it is only a single object.

    If you need further details, show us the code creating the table.

    A correct way of initializing table is

    table = [[1, 0, 0, 0] for i in range(3)]
    

    or simply

    table = [[1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a complete beginner to Python or any serious programming language for that
First, let me say that I'm a complete beginner at Python. I've never learned
I'm a complete beginner in Python and programming in general. I made a program
I'm still a beginner to Python, so I thought I could as well learn
Beginner in python, but been programming for about 5 years now. I suspect I
I am beginner in python and facing this problem. So how i can break
I am a beginner to Python so bear with me. Basically I am searching
I consider myself a very beginner at python(and programming in general!), but I am
I'm a beginner in programming and also a beginner in Python. Below are the
I'm a beginner in Python. My problem is pretty simple. I have a string

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.