Thread Shed

daily_transactions = daily_sales_replaced.split(',')
#print(daily_transactions)

daily_transactions_split = []
for transaction in daily_transactions:
  daily_transactions_split.append(transaction.split('+'))
#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(' '))
    transactions_clean.append(transaction_clean)
#print(transactions_clean)

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

for transaction in transactions_clean:
  customers.append(transaction[0])
  sales.append(transaction[1])
  thread_sold.append(transaction[2])
    
print(customers)
#print(sales)
#print(thread_sold)

So, when I print out the list "customers", each entry in transactions_clean appears four times.

I think the problem lies in the indentation of the statement

transactions_clean.append(transaction_clean)

If I am not mistaken, it should not be nested in the second for loop.

for data_point in transaction:
    transaction_clean.append(data_point.replace('\n', '').strip(' '))
transactions_clean.append(transaction_clean)
1 Like

Thank you! I’ve spent quite a while trying to figure this out!

transaction_clean.append has to be indented and 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. When you get such errors, move around the indentation in your code to see the results.

It’s a very slight difference that can’t really be detected in the “get help” video. (It’s–the fact that it’s not really clear-- been an issue for years that no one’s fixed.)
Also, there are many, many threads with this very same question. They are available via search.