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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:56:28+00:00 2026-06-10T20:56:28+00:00

I feel like I’m doing something very dumb here. Maybe I’m just too tired.

  • 0

I feel like I’m doing something very dumb here. Maybe I’m just too tired.

I’m trying to make a truth table with a size depending on “count” – the number of variables for the table.

    table = [[None] * int(pow(2, count))] * count
    in_a_row = pow(2, count) / 2
    iterator = 0
    for i in range(count):
        for j in range(int(pow(2, count))):
            print(str(i) + ' ' + str(j), end = '')
            if iterator < in_a_row:
                table[i][j] = 'T'
                print(' T')
            elif iterator == 2 * in_a_row:
                table[i][j] = 'T'
                iterator = 0
                print(' T')
            else:
                table[i][j] = 'F'
                print(' F')
            iterator += 1

        print(table)
        in_a_row /= 2
        iterator = 0

Which outputs this:

0 0 T
0 1 T
0 2 F
0 3 F
[['T', 'T', 'F', 'F'], ['T', 'T', 'F', 'F']]
1 0 T
1 1 F
1 2 T
1 3 F
[['T', 'F', 'T', 'F'], ['T', 'F', 'T', 'F']]

You can see what whatever I set in one iteration is echoed in all “rows”. Can anyone show me what’s wrong here?

I’m of course expecting this:

[['T', 'T', 'F', 'F'], ['T', 'F', 'T', 'F']]
  • 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-10T20:56:29+00:00Added an answer on June 10, 2026 at 8:56 pm

    Change the first line to:

    table = [[None] * int(pow(2, count)) for _ in range(count) ]
    

    as you’ve no doubt noticed, in the first version, each row shares a reference to the same list, whereas in this new version, we create a new list for each row.

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

Sidebar

Related Questions

I feel like I am missing something very simple here, but this is the
I feel like I'm missing something very obvious here, but I can't get a
I feel like there is something obvious I'm missing here. I am trying to
I feel like this is something I should already know, but I'm just not
I feel like I'm doing a lot of unnecessary stuff here: - (id)init {
I feel like there's something rather basic I'm missing here, which I previously thought
I feel like this is a very noob question.. but I just can't get
I feel like I'm missing something here, but I have this datagrid which when
I feel like this is a dumb question and I'm missing something, but I
I feel like I'm missing something blindingly obvious here, so low hanging fruit for

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.