My code is returning 4 times greater than whats supposed to and i dont know why

Hello, everyone

I’ve been studying this project and my code seems to be fine, but it is returning wrong numbers.

By ex 20, it is asked to use a function we create during the project to return the count of white threads sold. The answer is supposed to be 28, but mine is returning 112, four times greater than it should.

I went on to see where i made a mistake and i saw that on ex 15 my answer is also wrong, mine is returning 5994, but the answer is supposed to be 1498, which is also around a 4x difference.
I saw the results on the walkthrough video for the project on YouTube.

I analized every step of the lesson comparing with the walkthrough video and i couldnt find out what i have missed. For me it seems that my code is the same as in the video. What is wrong with my code?

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

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

transactions_clean = []
for i in daily_transactions_split:
  transaction_clean = []
  for j in i:
    list_values = j.replace('\n','').strip(' ')
    transaction_clean.append(list_values)
    transactions_clean.append(transaction_clean)
  
customers = []
sales = []
thread_sold = []
for i in transactions_clean:
  customers.append(i[0])
  sales.append(i[1])
  thread_sold.append(i[2])

total_sales = 0
for i in sales:
  value = i.strip('$')
  value_float = float(value)
  total_sales += value_float

thread_sold_split = []
for i in thread_sold:
  for j in i.split('&'):
    thread_sold_split.append(j)

def color_count(color):
  count = 0
  for i in thread_sold_split:
    if color == i:
      count += 1
  return count

You’re carrying out some series of steps, all of which are observable.

If you observe that there are four times as many as there should be, then you know the problem is earlier, and not later, so you would continue making observations earlier.
Similarly, if you observe that there are as many as there should be, then you know the mistake is later.

If there is too much data involved for you to be able to make those observations, then use less data.

1 Like

Great advice, thank you!

I used the first few instances of the given string and i printed step by step to see how every instance was changing with my code. Turn the problem was at the block

transactions_clean = []
for i in daily_transactions_split:
  transaction_clean = []
  for j in i:
    list_values = j.replace('\n','').strip(' ')
    transaction_clean.append(list_values)
    transactions_clean.append(transaction_clean)

There is an indentation mistake in the last line, i believe the reason that it was multiplying by 4 is because there is 4 elements in each sublist. The correct should be

transactions_clean = []
for i in daily_transactions_split:
  transaction_clean = []
  for j in i:
    list_values = j.replace('\n','').strip(' ')
    transaction_clean.append(list_values)
  transactions_clean.append(transaction_clean)

Thank you for your help!!