The project for Strings in Python 3 course

I am having the issue with this project. After step 9, the output came out 4 lists for each like,
[‘Lucille Caldwell’, ‘$5.13’, ‘white’, ‘09/15/17’], [‘Lucille Caldwell’, ‘$5.13’, ‘white’, ‘09/15/17’], [‘Lucille Caldwell’, ‘$5.13’, ‘white’, ‘09/15/17’], [‘Eduardo George’, ‘$20.39’, ‘white&yellow’, ‘09/15/17’], [‘Eduardo George’, ‘$20.39’, ‘white&yellow’, ‘09/15/17’], [‘Eduardo George’, ‘$20.39’, ‘white&yellow’, ‘09/15/17’], [‘Eduardo George’, ‘$20.39’, ‘white&yellow’, ‘09/15/17’], I have no idea why this is happening. My codes are:

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)

Can anyone help me?

Hello @ocmikae, welcome to the forums! The variable transaction seems to have four elements in it, which which means that this loop:

repeats four times for every time time the outer loop iterates:

2 Likes

This comes up a lot and I suspect it has something to do with the video. Many, and I do mean, many learners don’t make the connection between the inner loop and the outer loop as each having their own running variable. The inner loop has transaction_clean and the outer loop has transactions_clean. When they both exist in the inner loop we get the multiple entry problem. The latter should be unindented to put it back in the outer loop.


@catower, is this something that could be put on a priority for revising the video? It has come up a tonne in these past years.

3 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.