Python Project: Thread Shed. Where are all these multiples coming from?

https://www.codecademy.com/courses/learn-python-3/projects/thread-shed

Hi all,

I’m hoping you guys can help me with the Thread Shed string project linked above. I’m stuck on step 8. I’ll paste my code so far below too, but basically everything works perfectly until I get to step 8 where it asks me to iterate through the list in order to strip the whitespace from each transaction and append each cleaned up transaction to a new list. I’m able to accomplish this but it returns each transaction x4. So instead of a list with a list of unique transactions, I have a list with each transaction repeated 4 times. I even replaced this step with the code from the solution but I’m still getting the same result. I backtracked each step and the transactions don’t duplicate until I get to this step, so I’m not sure where I’m going wrong here. Thanks in advance!

# This is a portion of the string the project iterates through
daily_sales = \
"""Edith Mcbride   ;,;$1.21   ;,;   white ;,; 
09/15/17   ,Herbert Tran   ;,;   $7.29;,; 
white&blue;,;   09/15/17 ,Paul Clarke ;,;$12.52 
;,;   white&blue ;,; 09/15/17 ,Lucille Caldwell   
;,;   $5.13   ;,; white   ;,; 09/15/17,
Eduardo George   ;,;$20.39;,; white&yellow 
;,;09/15/17   ,   Danny Mclaughlin;,;$30.82;,;   
purple ;,;09/15/17 ,Stacy Vargas;,; $1.85   ;,; 
purple&yellow ;,;09/15/17"""
#------------------------------------------------
# Start coding below!

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

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)


# HERE is where the duplicates arise:
transactions_clean = []
for transaction in daily_transactions_split:
   clean_transaction = []
   for data_point in transaction:
      clean_transaction.append(data_point.strip())
      transactions_clean.append(clean_transaction)
print(transactions_clean)

Double check your indentation in your second for loop, here:

particularly the second .append()

It’s useful to use print() statements too and also write out what you think the code is doing at each step.

Also, some more discussion on this can be found here:

https://discuss.codecademy.com/search?q=thread%20shed%20step%208

1 Like