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

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:
# 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:

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:

1 Like