I'm struggling to understand this exercise?

Is this where we are to create a price list of all the cuts under 30 dollars?

Recall we have two lists, not one, but they do correspond with each other. We will iterate over the cuts list by index, then refer to that index in the prices list. If it is less than thirty, then add the cut to the new list.

cuts_less_than_30 = [hairstyles[i] for i in range(len(hairstyles)) if new_prices[i] < 30] 

The new list will only contain styles that are less than 30 dollars.

Have you studied iterators, yet (comprehensions are a form of iterator)? How about zip()?

cuts_less_than_30 = [cut for cut, price in zip(hairstyles, new_prices) if price < 30] 

In the above we have created a type of list made up of cut-price pairs that are unpacked on each iteration. If you are not yet familiar with zip() then set this solution to the side and come back when you get into that unit.

Thanks a lot for your effort, guess I’m slowly getting some confidence about working with list in loops!

1 Like