Python 3 - Strings: Thread Shed, exercise 8

Hi coders!

In exercise 8 of the Thread Shed project, the code goes as follows to clean up white space from a list of strings we generated in previous steps.

transactions_clean =
for transaction in daily_transactions_split:
transaction_clean =
for item in transaction:
transaction_clean.append(item.strip())
transactions_clean.append(transaction_clean)

I totally get why we need two for loops here. What I am confused about is the reason for the empty list transaction_clean after the first for loop. Why can’t I just directly append the item.strip() result to the empty list transactions_clean??
Is there a rule for when I would need to create a list within the first loop when trying to access an item within a list within a list?

Thank you in advance for the help!
Happy learning :slight_smile:

Hello! I think the reason is that in transactions_clean, each transaction ought to be in a list of its own.

Thank you! So then it’s just specific to this particular exercise and the need to have transactions in list format to move on?

Yes, as far as I know.

1 Like