0

So, I currently have a pretty convoluted list of lists of lists, that I've been able to manage pretty easily; however, I've had to essentially duplicate that list X times as the data thats being stored is now being divided even more.

Essentially it consists of

#ALL CARDS
[
     
    #CARD 0
    [

        #Component 0 
        [
            #0
            [   #A
                #Time, Min, Avg, Max
                [[], [], [], []], 
                #B
                #Time, Min, Avg, Max
                [[], [], [], []]
            ], 
            #1
            [   #A
                #Time, Min, Avg, Max
                [[], [], [], []], 
                #B
                #Time, Min, Avg, Max
                [[], [], [], []]
            ],  
            #2
            [   #A
                #Time, Min, Avg, Max
                [[], [], [], []], 
                #B
                #Time, Min, Avg, Max
                [[], [], [], []]
            ], 
            #3 
            [   #A
                #Time, Min, Avg, Max
                [[], [], [], []], 
                #B
                #Time, Min, Avg, Max
                [[], [], [], []]
            ],  
            #4
            [   #A
                #Time, Min, Avg, Max
                [[], [], [], []], 
                #B
                #Time, Min, Avg, Max
                [[], [], [], []]
            ], 
        ], 
        #Component 1
        [
            #Time A, Time B, Value A, Value B (repeated 5 times for each sub component)
            [[], [], [], []],
            [[], [], [], []], 
            [[], [], [], []], 
            [[], [], [], []], 
            [[], [], [], []]    
        ], 
        #Time, Min, Avg, Max for each of the components below. They are single instances and have no sub like the above 2
        [[], [], [], []], #Component 2 
        [[], [], [], []], #Component 3
        [[], [], [], []], #Component 4 
        [[], [], [], []], #Component 5 
        [[], [], [], []], #Component 6 
        [[], [], [], []], #Component 7 
        [[], [], [], []], #Component 8 
        [[], [], [], []], #Component 9 
        [[], [], [], []], #Component 10
        [[], [], [], []] #Component 11
    ],
    #INTF Card 1-3 Set up Same way

^ This structure is taken directly from a print out of the empty list.

NOW, the issue is, that when I'm parsing through text to grab the values and store them in their respective spots, I'm getting duplicates, despite the fact that I'm intentionally calling out specific spots in the list.

An example is when I try to .append() a value to it such as

all_cards[0][2][0].append("4")

it will append the value 4 to the first list (Time) in the Component 2 list, BUT it will append it to each card (0-3), instead of just the Card 0 like is being called out by the "all_cards[0]" part.

I DO understand this isn't the best way to have built up this data, but the program got feature-creeped, and I am trying to get a working version usable before I try to rewrite to get a chance to rewrite this entire program....

If anyone knows why this data is duplicating across each card in the all_cards list it'd be appreciated thanks.

I've tried indexing the list in different ways, but keep either ending out of range, or getting duplicates across cards

  • 2
    This is because you have used the *same* list multiple times during the initialization phase -- code you have not shown. – trincot Aug 21 '23 at 20:17
  • Wait, I did do this exact thing.... I have the initialization set up as all_cards = [interface_card, interface_card, interface_card, interface_card] So it references them as the same place in memory? – Kyle Clark Aug 21 '23 at 20:28
  • Yes, that's how it works. – trincot Aug 21 '23 at 20:30
  • Yes, `interface_card` is the same object every time. – mkrieger1 Aug 21 '23 at 20:30
  • Okay cool! Lesson learned! Thank you so much for your time and help!! – Kyle Clark Aug 21 '23 at 20:32
  • You could copy the list with `[interface_card[:], ...]` but if that list is guaranteed to be empty (or you want empty lists) do `[[], [], ...]`. Bascially do what the printout looks like. – tdelaney Aug 21 '23 at 20:35
  • Yea I was just looking into the best way to do that. I was trying to be to compact/readable/manageable with my code. I think I'll try the [:] method like you mentioned. I'd rather not fill up the screen with 200 empty brackets that I'll need to redecypher every time something changes... – Kyle Clark Aug 21 '23 at 20:54

0 Answers0