Thread Shed

So I’m trying to complete the Thread Shed project, but when I create a for loop inside another for loop, it repeats multiple times. My goal is removing unnecessary whitespace and newlines, but it looks different from the video. After I got confused, I looked at the video and copied his code, yet the same problem still occurs. Why does the same string repeat many times?

daily_sales_replaced = daily_sales.replace(';,;', '|')
daily_transactions = daily_sales_replaced.split(',')
#print(daily_transactions)

daily_transactions_split = []
for string in daily_transactions:
  daily_transactions_split.append(string.split('|'))
#print(daily_transactions_split)

transactions_clean = []
for transaction in daily_transactions_split:
  transaction_clean = []
  for data in transaction:
    transaction_clean.append(data.strip(' '))
    transactions_clean.append(transaction_clean)
print(transactions_clean)
1 Like

The same thing happens when I add the customer names, sales, and the thread sold. ALL of it repeats 4 times.

It goes like this:

name1, name1, name1, name1, name2, name2, name2, name2
sales1, sales1, sales1, sales1, sales2, sales2, sales2, sales2
color1, color1, color1, color1, color2, color2, color2, color2

So you’re saying you have something in a loop that shouldn’t be repeated? Move it outside the loop then.
Better to consider the problem and adjust accordingly, than to copy.
You can also use prints to write out stuff like what a list looks like before and after doing something, which you can use to narrow it down. Printing can also be done to write out what is being done, so that you can compare what was done to what you meant should be done.

3 Likes