Thread Shed Project Question (possibly just indent issue in for loop)

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

So I was having a ton of issues figuring it out, had one way that was more hard coded and not as organized, using ranges to go through the index’s because I was having issues with the for loops and the lists at different times.

ANYWAY…

I opened the stuck video and tried to do it how he did it, didn’t work, so I scrapped the whole thing and literally copied down word for word what he did and am still getting a huge propblem.

So, everything is going fine up until this part in the code: (PS THE INDENTS IN THE FORUM ARENT WORKING FOR THIS PART IDK WHY BUT I DO HAVE THEM INDENTED)

Edit: Issue resolved I just read the starter forum for proper code format, my apologies.

transactions_clean = []
for transactions in daily_transactions_split:
  transaction_clean = []
  for data_points in transactions:
     transaction_clean.append(data_points.replace("\n", "").strip())
     transactions_clean.append(transaction_clean)

The issue is at the bottom for the:

 transactions_clean.append(transaction_clean)

line, it has each item in the list printed out 4 times. When I remove an indent to the bottom one, then it prints them out one at a time, but now the function afterwards when you append the customer/sales/etc lists has issues.

Why is it doing this? Why is it when I watch the video to “get unstuck” and do line for line, his comes out just fine? 5:05 IN YOUTUBE VIDEO.

Can anyone tell me what I am doing wrong?

Here is my full code so that you people who always ask for more information don’t have to.

# Start coding below!

## Starting by splitting the code.

daily_sales_replaced = daily_sales.replace(";,;", ";")
#print(daily_sales_replaced)
daily_transactions = daily_sales_replaced.split(",")
#print(daily_transactions)

daily_transactions_split = []
for transactions in daily_transactions:
  daily_transactions_split.append(transactions.split(";"))
#print(daily_transactions_split)

transactions_clean = []
for transactions in daily_transactions_split:
  transaction_clean = []
  for data_points in transactions:
    transaction_clean.append(data_points.replace("\n", "").strip())
    transactions_clean.append(transaction_clean)

#print(transaction_clean)
print(transactions_clean)

customers = []
sales = []
thread_sold = []

We cannot tell where your indents are but can see a nested loop and two different lists, one being cleared each time through the outer loop. Be sure that the append statements are not both in the inner loop.

1 Like
for transaction in transactions_clean:
  customers.append(transaction[0])
  sales.append(transaction[1])
  thread_sold.append(transaction[2])

print(customers)
print(sales)
print(thread_sold)

this (next part from video) gives me:

['Edith Mcbride', 'Edith Mcbride', 'Edith Mcbride', 'Edith Mcbride', 'Herbert Tran', 'Herbert Tran', 'Herbert Tran', 'Herbert Tran', 'Paul Clarke', 'Paul Clarke', 'Paul Clarke', 'Paul Clarke', 'Lucille Caldwell', 'Lucille Caldwell', 'Lucille Caldwell', 'Lucille Caldwell', 'Eduardo George', 'Eduardo George', 'Eduardo George', 'Eduardo George', etc.....

While in the video he gets all of them just once. Makes no sense.

Pretty the new user starter’s guide covers how to post code samples. Did you read that section when you joined the forums?

Yeah I said don’t worry about the indents because it’s not executing the quote properly. Please read fully.

Thank you, if you want to see the code, go to Thread Shed Project in strings for Learn Python3, watch the video, I put the time stamp, 5:05, look at the code he’s writing I have it indented exactly the same.

Watched it over and over trust me, sat here for nearly 2 hours rewriting it perfectly.

I did, and it doesn’t change my answer.

Which is the problem. They cannot both be in the same loop.

Please learn how to post code in the forums.

# Start coding below!

## Starting by splitting the code.
daily_sales_replaced = daily_sales.replace(";,;", ";")
#print(daily_sales_replaced)
daily_transactions = daily_sales_replaced.split(",")
#print(daily_transactions)

daily_transactions_split = []
for transactions in daily_transactions:
  daily_transactions_split.append(transactions.split(";"))
#print(daily_transactions_split)

transactions_clean = []
for transactions in daily_transactions_split:
  transaction_clean = []
  for data_points in transactions:
    transaction_clean.append(data_points.replace("\n", "").strip())
    transactions_clean.append(transaction_clean)

#print(transaction_clean)
#print(transactions_clean)

customers = []
sales = []
thread_sold = []

for transaction in transactions_clean:
  customers.append(transaction[0])
  sales.append(transaction[1])
  thread_sold.append(transaction[2])

print(customers)
print(sales)
print(thread_sold)

I mean you coulda just said hit the preformatted text button instead of the blockquote, but I get it, you see it everday. No worries boss.

As suspected, the second append should outdented so it is in the outer loop.

2 Likes

Yep worked perfectly! Thank you!

1 Like

Also, the main reason I was having an issue was that the video I cited doesn’t obviously show that outdentation in the walkthrough.

Not sure if I should be reporting that to you or elsewhere but yeah just thought I’d throw that out there as a heads up for anyone reading with same problem.

Link: https://www.codecademy.com/courses/learn-python-3/projects/thread-shed >> get unstuck >> walkthrough video >> timestamp: 5:05

transactions_clean = []
for transactions in daily_transactions_split:
  transaction_clean = []
  for data_points in transactions:
     transaction_clean.append(data_points.replace("\n", "").strip())
  transactions_clean.append(transaction_clean)

Is what it should look like in the video (box sizes of text area, python script, and output window are slimmed down and probably the reason for the indentation problem in video) for anyone else with issue.

I’ll take a look at the video and if there is a discrepancy, will pass it up to HQ. I’ve seen this problem for some time now so you are probably not alone in your observations.


Have seen the video and line 124 should not have the same indent as line 123. Have no idea how he gets the correct print out, but then we can only see a tiny bit of it.

@lilybird, can you please ask someone to check the video and maybe annotate that segment to advise outdenting of line 124? Thanks.

3 Likes

I see what you mean!
I recall asking myself the same thing when I did the project. :woman_facepalming:t2:

2 Likes

Yeah exactly! Thank you for the screenshot!

I tried to watch also in real time to see if he does a dedent or indent and I swear I don’t see anything move.

Line 124 is properly out-dented in the video. Line 123 is also at the proper indentation level, but gets shifted down and to the left by the code editor when the length of the line surpasses the width of the code editor. If the instructor were to widen the editor, it would shift back. The screenshot in @lisalisaj’s post shows what I’ve described. What may be missing here, on the part of learners, is an understanding of indentation in Python. If one knows what the code is doing, one should understand what belongs in each loop. It would be a nice addition to the video if the instructor mentioned why line 123 gets moved around, and that line 124 is out-dented so as not to be included in the inner for loop.

3 Likes

Yeah, I blamed the visuals on zooming and too narrow a view port. One supposes that during this step it would be handy to close the console for the moment so the code arrangement stands out better.

4 Likes
print ("Rows cleaned")
transactions_clean = []
for row in daily_transactions_split:
  for col in range(len(row)):
    row[col] = row[col].strip()
  transactions_clean.append(row)
  print (row)

Mind, my code looks nothing like the video, as usual.

Indentation is mentioned on the DS path, but the degree to which I do not know/recall [even though I’m on the path. :joy: I was/am mindful of indentation prior to starting the path]. I haven’t gone over all the new materials that were recently added, so, maybe there’s some newer stuff that I’ve not yet seen.

In most languages, indentation is trivial (other than improving legibility for humans), but given this is Python, the instructor really should have mentioned what happened when the code editor nudged the line out of place. Also, Happy Cake Day!

1 Like

I will create a bug report for the team. Thanks for flagging.

Edit: the bug report has been created. I’ll follow up once the team has a look.

3 Likes