Need Help With Thread Shed :<

I genuinely can not figure out what I am messing up. I know I did something wrong in step 8 that’s making it impossible to do step 11. I keep trying to solve it myself but I am just so stuck. Can someone please tell me where I am screwing up at? It’s only appending letters and not strings and any change I make just makes it worst. I have watched the developer video and read a few posts on here and I still can’t figure it out. Code is pasted below:

daily_sales_replaced = daily_sales.replace(';,;', '&')
daily_transactions = daily_sales_replaced.split(',')

daily_transactions_split = []
for i in daily_transactions:
  daily_transactions_split.append(i.split('&'))

transactions_clean = []
for word in daily_transactions_split:
  for data in word:
    transactions_clean.append(data.replace('\n', '').strip(' '))
    transactions_clean.append(transactions_clean)

#print(transactions_clean)

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

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

I found some problems in the loops creating transactions_clean

You have   transactions_clean.append(transactions_clean)
which appends transactions_clean to itself. That should not be there. Delete it.

Also, you should be appending lists to transactions_clean, not strings.
You can create such a list in the outer loop, append to the list in the inner loop,
and then append the list to transactions_clean in the outer loop.
( I think the idea is to have transactions_clean be a 2D list with the same structure as daily_transactions_split .)

transactions_clean = []
for word in daily_transactions_split:
  word_clean = []
  for data in word:
    data_clean = data.replace('\n', '').strip(' ')
    #print(data_clean)
    word_clean.append(data_clean)
  transactions_clean.append(word_clean)

I used a list comprehension when I did the project:

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

print(transactions_clean)
2 Likes

Thank you so much for taking the time and effort to explain that to me! It means a lot! Thank you!

1 Like