Hi! I have finished the excercise and got the correct prints before looking up the solutions. The way I have done some of the steps is different than what the description was suggesting to do. In particular I have been trying to do step 11 as suggested, but was failing and decided to do it like this:
customers = transactions_clean[0::4]
sales =transactions_clean[1::4]
thread_sold = transactions_clean[2::4]
After finishing the excercise I have skimmed through the YouTube video and tried doing:
customers =
sales =
thread_sold =
for transaction in transactions_clean:
customers.append(transaction[0])
sales.append(transaction[1])
thread_sold.append(transaction[2])
But what I get printed after this are the first, second and third characters in transaction. So I guess it is string vs list problem, but I don’t really grasp where does the difference come from?
This is the full code I wrote for the excercise(with the 2nd method on step 11 omitted by #):
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 i in daily_transactions_split:
for a in i:
transactions_clean.append(a.strip())
customers = transactions_clean[0::4]
sales =transactions_clean[1::4]
thread_sold = transactions_clean[2::4]
#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)
#Total value
total_sales = 0
for i in sales:
value = float(i.strip("$"))
total_sales += value
#print(total_sales)
#How much thread of specific color
thread_sold_split = []
for i in thread_sold:
if i.find("&") == -1:
thread_sold_split.append(i)
else:
b = i.split("&")
for c in b:
thread_sold_split.append(c)
#print(thread_sold_split)
def color_count(color):
count = 0
for i in thread_sold_split:
if i == color:
count += 1
return count
#print(color_count("white"))
colors = ['red','yellow','green','white','black','blue','purple']
for i in colors:
x=color_count(i)
print("Thread Shed sold {count} thread of {color} thread today.".format(color = i, count = x))
Is what I wrote wrong in some way?
Thanks