Carly's Clippers

I am doing the Carly’s Clippers exercise and I am wondering why they always use new_list[i]. What does the [i] stand for? I can see it also with last_week[i]. I am not sure if I totally understand what that means and how it came about. How did we create this i? I believe we created it in
for i in range(len(hairstyles)):
total_revenue += prices[i] + last_week[i]

But I am still not sure what it stands for and how we created it.

The range function is designed to create a sequence of numbers. If you want to know what i is, then consider printing the output, for example-

for i in range(5): print(i)

As for why we’re using this it is to index our list. Say we have a list of 5 items-

test = ["red", "orange", "yellow", "blue", "indigo"]

We want to access a particular item from our list, say the second item "orange". We can use an index with our list to do this (remember than our index starts at 0).

print(test[1])  # index starts at 0, [1] is the 2nd item!
Out: 'orange'

By combining the use of range to get a sequence of numbers and using these values to index our list we can access each element of our list in turn. Or, in this case, two lists at the same index.

1 Like

Aha, now I understand, thanks a lot!! Great explanation.

1 Like