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

  • Home
  • SEARCH
  • 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 6628067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:05:16+00:00 2026-05-25T22:05:16+00:00

Ok, with the same program previously I’ve now hit a problem I should have

  • 0

Ok, with the same program previously I’ve now hit a problem I should have anticipated; the grid (of variable width and height) is constructed based on a code to alternate the symbols which creates a list, those lists are then stored in the grid as nested lists. below is a section of code for making the list (called line) the odd numbered width is necessary.

1 - + -
2 + - + 
3 - + -

   if gridwidth % 2 != 0: 
        for i in range(gridwidth):
            if i % 2 == 0:
                line.append('-')
            else:
                line.append('+')

Edit – sorry I didn’t want to spam with code; the lines are put into the list grid below;

    grid = []
    for i in range(height):
        if i % 2 == 0:
            grid.append(line)
        else:
            grid.append(linerev)

line is then appended to grid by the range(height) and there is another block of code to handle the alternating lines which creates another list (linerev) – my problem is that because of how the grid is created, if I try to change a value in it say turn grid[0,0] into a + or -, it changes it along several rows as grid[1,0], grid[5,0] etc are all referring the the same list – is there any way to avoid this without using global variables, deep copy, or drastically revising how the grid is created? Any help would be much appreciated.

  • 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-25T22:05:16+00:00Added an answer on May 25, 2026 at 10:05 pm

    The easiest way is to make copies of the lists when you add them:

    grid = []
    for i in range(height):
        if i % 2 == 0:
            grid.append(line[:])
        else:
            board.append(linerev[:])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is about the same program I previously asked about . To recap,
Regarding the same program as my question a few minutes ago ... I added
After providing the same program which reads a random generated input file and echoes
How can I avoid that a user starts the same program twice? The current
Here is some dprofpp -I output, for almost the same program on different input
What is the right place to store program data files which are the same
I need to accomplish the same behavior as .NET Console.ReadLine function provides. The program
We have a few different programs all compiled together in the same suite, recently
I have a (C#) genetic program that uses financial time-series data and it's currently
I've just repackaged my program. Previously all modules lived under the whyteboard package, with

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.