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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:26:47+00:00 2026-06-06T21:26:47+00:00

I’m looking for a way to do the following: I have a list composed

  • 0

I’m looking for a way to do the following:

  • I have a list composed of other lists:TABLE=[table1,table2,table3]
  • I would like to duplicate this list but rename the sublists, such as:TABLE_1=[table1_dup=list(table1),table2_dup=list(table2),table3_dup=list(table3)] (this doesn’t work; I’m just trying to explain my goal) so that I can access tablex and tablex_dup independently after performing batch operations on the whole TABLE and TABLE_1, which include table1, table2, … and the duplicates.

Thanks a lot!

EDIT: The sublists aren’t necessarily named the same (table1, table2, table3). Actually, their names are quite different (e.g. up, down, left, right)

EDIT #2:
I’m kinda new to this. Basically, here’s my code:

up=["img1.png","img2.png"]

similar things for down, left and right.

table=[up,down,left,right]

Now using pygame:

for j in range(len(table)):
        for i in range(len(table[j])):
            table[j][i] = pygame.image.load(os.path.join(str(table[j][i])))
            table_r[j][i] = pygame.image.load(os.path.join(str(table_r[j][i])))
            table_r[j][i] = pygame.transform.flip(table_r[j][i],1,0)

This wouldn’t work as there is no up_r, for example, that I could access. Only up.

  • 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-06T21:26:48+00:00Added an answer on June 6, 2026 at 9:26 pm

    On the more general issues raised in the comments and by your edits – it seems very much like a list of lists isn’t the right data structure for your logic here. A list is usually indicated when you can have arbitrarily many ‘rows’ in your table – it seems you always have exactly four. A tuple is better in this case – it is kindof like a list, except it is set up more deliberately for things that don’t change. And, even better, since you want to address your four things by name, there’s a standard Python class called collections.namedtuple that makes this easy.

    You would define a Table class like this:

    Table = namedtuple('Table', ['up', 'down', 'left', 'right'])
    

    And then you create your first table like this:

    table = Table(up=["img1.png","img2.png"], down=..., left=..., right=...)
    

    This lets you get your ‘up’ list as table.up, which means when you do a deepcopy into table_r per Constantinius’ answer, these names come with it for free. And it also lets you iterate over it in exactly the same way as your list:

    for i in range(len(table)):
        for j in range(len(table[i])):
           ...
    

    However, note that iterating over range(len(iterable)) is usually not necessary – since you’re using the index to look up values from your two tables simultaneously, what you really want is a combination of the builtin functions enumerate and zip:

    for row, row_r in zip(table, table_r):
        for i, (val, val_r) in enumerate(zip(row, row_r)):
           row[i] = pygame.image.load(os.path.join(str(val)))
           row_r[i] = pygame.image.load(os.path.join(str(val_r)))
    

    You only need the index to assign into the lists, since rebinding val and val_r inside the inner loop won’t work. Since you don’t use j as anything other than a lookup, you don’t need it at all.

    But this also brings up the one caviat of using a namedtuple – the one thing it can’t do that you might care about is change an attribute of the tuple after it is created:

    >>> from collections import namedtuple
    >>> Point = namedtuple('Point', ['x', 'y'])
    >>> p = Point(1, 2)
    >>> p.x = 2
    Traceback (most recent call last):
      File "<pyshell#3>", line 1, in <module>
        p.x = 2
    AttributeError: can't set attribute
    

    In your case, this means you can’t reassign table.up to a new list at any point (you can still change the list itself, though, through its mutation methods and slice assignment) – if you need that, you’re best off coding your own class for this.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have two tables with like below codes: Table: Accounts id | username |
I have a jquery bug and I've been looking for hours now, I can't
I would like to count the length of a string with PHP. The string
I would like to run a str_replace or preg_replace which looks for certain words
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.