# Don’t really grasp where does the difference come from?

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]
``````

After finishing the excercise I have skimmed through the YouTube video and tried doing:
customers =
sales =
for transaction in transactions_clean:
customers.append(transaction[0])
sales.append(transaction[1])

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]
#for transaction in transactions_clean:
#  customers.append(transaction[0])
#  sales.append(transaction[1])
#print(customers)
#print(sales)

#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
if i.find("&") == -1:
else:
b = i.split("&")
for c in b:
def color_count(color):
count = 0
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)

``````

Is what I wrote wrong in some way?
Thanks

1 Like

No, you did a great job. Just make sure that you understand how the code in the video works.

In Python, the magic of for-in means that we often do not need to use indexing at all, or if we use it, we often are able to omit one level of indexing in nested lists. It’s rare to see slicing used to break them down. (In plain Python, that is; in Numpy & Pandas it’s quite common!)

Anyway,

Yes.

“Your” transactions_clean list is a list of strings:
` ['Edith Mcbride', '\$1.21', 'white', '09/15/17', 'Herbert Tran'... etc. ]`
so one transaction from transactions_clean is a string:
`'Edith Mcbride'`
… making transaction[0], transaction[1], etc, separate characters, ‘E’, ‘d’, ‘i’, etc.

Whereas “their” transactions_clean list is a list of lists of strings:
`[['Edith Mcbride', '\$1.21', 'white', '09/15/17'], ['Herbert Tran',...etc], etc]`
… so one transaction is a ` list`:
`[['Edith Mcbride', '\$1.21', 'white', '09/15/17']`
… making transaction[0] a string: `'Edith Mcbride'`

1 Like

Hi noispaxen.

I hope you can help me a little bit.

if i.find(“&”) == -1:
else:
b = i.split(“&”)
for c in b:

In this code that you wrote, can you explain me the “-1” after che t i.find(“&”)? Why have you put that one? In that case i prefered to write this, although, I believe that It is not right.