Learn python strings/projects/thread-shed/unable to replicate method shown on video lesson

Hello, I was wondering if anyone had an idea of what i did wrong. I am having a problem with task 8 of this project.

“”"It looks like each data item has inconsistent whitespace around it. First, define an empty list transactions_clean .

Now, Iterate through daily_transactions_split and for each transaction iterate through the different data points and strip off any whitespace.

Add each of these cleaned up transactions to the new list transactions_clean“”"

so after a bit of trying i decided to follow the step by step video with the project and that solution that is shown and explained causes my terminal console to show me 4 repeated entries per actual entry:

“”"[[‘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’], “”"

as you can see this is only the first name. it does this to each name in the project. The code i put in is exactly as explained on the video.
“”"
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)"""

anyone know the correct way of handling this issue. i have reviewed the previous code and they print out their reported statements so why is this one giving me a problem.

please and thank you.

https://www.codecademy.com/paths/computer-science/tracks/cspath-python-objects/modules/cspath-python-strings/projects/thread-shed

Hi,

It’s a little hard to be sure without your code being formatted here (press </> before pasting: from this bar:Screen Shot 2020-09-23 at 11.17.21 AM )

But for sure I think the issue is around this line of code:

transactions_clean = []
for transaction in daily_transactions_split:
  transaction_clean = []

Because no matter what you run in the above quoted loop, you will be resetting the value of transactions_clean at every iteration (which is not the desired effect in this circumstance).

1 Like
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 hope this is much more readable. I believe that the line you pointed out is the problem but what would be a suggested fix. btw this line of code is exactly the same as it was typed in on the project walkthrough video which is why i’m so confused as to why my list get multiplied into 4 repeated list.

I think the first step is to ignore what the video is saying (at least in that part). In general, if I can’t logically follow what a video is doing, I don’t find it useful to copy the code. Even if I’m following videos that are well-esteemed, I try to doubt the video and verify for myself at each step (within reason) until I convince myself that it has logic. It’s a little slower but I think it’s more useful.

I think the directions actually don’t say to write transactions_clean twice. But the most useful way to solve it is to write out in English sentences what you want to achieve with the code, and then write the code that reflects that. It may take just a little bit longer, but it’ll increase your precision.

2 Likes