Thread-shed making 4 copies of each of the lists

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

Somewhere around step 8 or 9 something happens and I suddenly have 4 of each list.
print statement looks like this for each list:
[[‘Edith Mcbride’, ‘$1.21’, ‘white’, ‘09/15/17’],
[‘Edith Mcbride’, ‘$1.21’, ‘white’, ‘09/15/17’],
[‘Edith Mcbride’, ‘$1.21’, ‘white’, ‘09/15/17’],
[‘Edith Mcbride’, ‘$1.21’, ‘white’, ‘09/15/17’],

Here is my code up to this point:
#------------------------------------------------

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)

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)

I feel like it could be an indentation thing with the for loop so it is appending it 4 times but it looks exactly like the video and it works in the video… please help :slight_smile:

Hello @a_dam_rut, welcome to the forums!

This thread may be of help. Essentially, the last loop is looping through transaction four times, and as such is creating four times too many lists. You are indeed correct in your assumption that indentation is the issue. Look at this line, and consider its indentation:

 transactions_clean.append(transaction_clean)

This thread may also help.


Also, in future, please make sure to format your code according to this guide; thanks!

1 Like

Thank you! that fixed the issue. I was suspecting that it was an indentation error on that line. I was so close!

1 Like