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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:40:04+00:00 2026-06-11T03:40:04+00:00

I am trying to set a specific value of a 2D array to True.

  • 0

I am trying to set a specific value of a 2D array to True. Here is the snippet of code:

b [ [False] * 3] * 3
b[2][1] = True 

Unfortunately, this is setting the entire row to True (so b[0][1] would then be changed to True). Any ideas on what is going on?

EDIT:

Just tried this code and it worked:

 b = []
 for i in range(3):
     b.append([False, False, False])
 b[1][2] = True

Why would it work in that case and not the former?

  • 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-11T03:40:06+00:00Added an answer on June 11, 2026 at 3:40 am

    [[False]*3]*3 creates three references to the same [False,False,False] object, thus when you change one item, your other rows/cols change as well.

    Your second version avoids this by createing a new [False, False, False] object for every row/col.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set a sequence to a specific value. SELECT setval('payments_id_seq'), 21, true;
I'm trying to set an option with a specific value as selected (using jQuery).
I have been trying to set AlarmManager for Specific date, but it is not
I am trying to pull a specific set of records from a table called
I'm trying to set an input box with a specific internal height, and I'm
I'm trying to write a predicate to check a specific value in a dictionary
This is a very odd, and quite specific question. Ultimately I am trying to
I am trying to loop through only a specific sub array in PHP with
I'm trying to set a win32 console application's font color to a specific RGB
I am trying to find a specific TreeViewItem whose Tag property is set to

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.