Thread Shed task 7-9

I need help with these steps in the project. My result is not what it should be and i can’t figure out what’s going wrong

transactions_clean =

for transaction in daily_transactions_split:

transaction_clean =

for data_point in transaction:

transaction_clean.append(data_point.replace("\n", "").strip(" "))

transactions_clean.append(transaction_clean)

print(transactions_clean)

When I print this out my expected result is a list of each list one time however the result i get is a list with 4 of each list which makes the next task of totaling the sales incorrect. this is just part of the output but you get the idea

[[‘Edith Mcbride’, ‘$1.21’, ‘white’, ‘09/15/17’], [‘Edith Mcbride’, ‘$1.21’, ‘white’, ‘09/15/17’], [‘Edith Mcbride’, ‘$1.21’, ‘white’, ‘09/15/17’], [‘Edith Mcbride’, ‘$1.21’, ‘white’, ‘09/15/17’], [‘Herbert Tran’, ‘$7.29’, ‘white&blue’, ‘09/15/17’], [‘Herbert Tran’, ‘$7.29’, ‘white&blue’, ‘09/15/17’], [‘Herbert Tran’, ‘$7.29’, ‘white&blue’, ‘09/15/17’], [‘Herbert Tran’, ‘$7.29’, ‘white&blue’, ‘09/15/17’], [‘Paul Clarke’, ‘$12.52’, ‘white&blue’, ‘09/15/17’], [‘Paul Clarke’, ‘$12.52’, ‘white&blue’, ‘09/15/17’],

I don’t see what i am doing wrong in the for loop to make the lists multiply like this I’m losing my mind trying to figure this out.

Be sure those two lines are in separate loops. One on the inner, the other outer.

1 Like

When I watched the solution video to see what I was doing wrong this is exactly how he has it. I will try that and see thank you.

1 Like

Well I added the second line of transactions_clean.append(transaction_clean) to the first loop and it printed the correct output but I am unsure as to why.

1 Like

It helps if we have a white board or paper and pencil to sketch out the iterations, and how the data structures are mutated along the way.

The desired output is the result of appending data to an intermediate object, which once built up is then appended to the primary object.

It’s important to build up the intermediate object to completion, then exit that loop and append to the primary object.

The intermediate object is transient, and gets recreated each iteration of the outer loop.