Thread Shed. Why is my code printing four times

in thread shed, when i get to the point where i am printing to the console the print has each item in the string printing each item four times,

[[‘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’],

daily_sales_replaced = daily_sales.replace(";,;","+")

daily_transactions = daily_sales_replaced.split(",")

daily_transactions_split = []
for transaction in daily_transactions:
# print(daily_transactions_split)

transactions_clean = []
for transaction in daily_transactions_split:
  transaction_clean = []
  for data_point in transaction:
    transaction_clean.append(data_point.replace("\n","").strip(" "))


customers = []
sales = []
thread_sold = []

for transaction in transactions_clean:
# print(customers)
# print(sales)
# print(thread_sold)
total_sales = 0
for sale in sales:
  total_sales += float(sale.strip("$"))
# print(total_sales)

I’m losing my mind, I’m going through the walkthrough. I don’t know what I am doing wrong

You might find your answer here. There are several threads that ask the same question:

What many of those same threads will point out & I will point out is:
check your indentation on that second for loop. More specifically,


When you encounter errors like that, switch up the indentation and see what happens/take note of what the code is doing.
The reason you’re getting the output you are is b/c “transactions_clean.append” has to be at the outside level of the inner for loop, otherwise you’re cleaning, appending and then appending again, which would give you duplicates.

Thank you! I really appreciate the help!

1 Like