Python 3 _ Thread-shed

Hi I have a question regarding below course

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

So, at task 8, I realized that I was not getting the expected result (list in list) because I defined a new list outside of the loop.
I quite don’t understand why is that…
What makes it different?

//WRONG//
transactions_clean =
transaction = []
for i in daily_transactions_split:
for k in i:
transaction.append(k.strip())
transactions_clean.append(transaction)

//CORRECT//
transactions_clean =
for i in daily_transactions_split:
transaction = []
for k in i:
transaction.append(k.strip())
transactions_clean.append(transaction)

2 Likes

In the second example we are re-using the list, starting from empty on each iteration.

1 Like