Thread shed gets printed 4 times in a row for every element

Hey! I have a problem with Thread Shed project (https://www.codecademy.com/courses/learn-python-3/projects/thread-shed)

Here’s my code:

daily_sales_replaced = daily_sales.replace(";,;", "+")
#print(daily_sales_replaced)
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)

But the thing is that EVERY element gets printed four times. Why is that and how do I solve it?

The number of repeats might give you a hint of where this issue might arise. What sections of code do you have to repeat tasks? Consider what you’re you’re asking to be done in those sections and whether that actually matches what you want to happen. If you’re unsure a couple of print statements or a similar method of debugging might help you locate any problems.

Well I followed the tutorial on the Internet on that task and my code is IDENTICAL but still it gives different output. I can’t get it.

It’s important to understand your own code in its entirety. Copy/pasting is always risky and it’s not great for learning either. Even if you find a solution to a problem you should then break it down a bit. What does each line do? When is that line executed? What would be the output? These are things you have to know and not things you can just guess at. Your main goal in these lessons is to understand the content. Just passing the lesson should not be your main goal, it risks being just a false sense of achievement.

I’ve left a hint about where to find your error and suggested a very basic method of debugging. I’d strongly encourage you to start working this way as you’ll be solving problems like this all the time. It’s a good skill to learn.

1 Like