# 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

I am pretty sure the +=, and the -= operators were defined and used at the very beginning of the course, because I am using them quite a bit so far.

AGREE AGAIN. Another poorly presented section. up until now, great, but codeacademy needs to rewrite this section:
more examples
more explanation
clearer content

Thanks for posting this. This has been the issue with me as well. When I look at the solution I can see that it was different than what they asked in the instructions. I have spent a few days dwelling and redoing this section just so I can fully comprehend it. I hate moving on to the next chapter or topic without knowing what I did. It is frustrating but glad to know that I am not alone.

1 Like

Hi there!

So I ran into an interesting problem. I used your examples and when I got to the āprint(squares)ā line and section of the exercise it printed the whole thing 9 times. I did all the steps exactly as you said to try and avoid any errors in that way. It doesnāt appear that the instructions want me to break the loop, but for some reason that very code is giving me an output 9 times. Iām going to reset and try one more time copy and pasting what you suggested in to make sure Iām not crazy, but I donāt see where it would even ask the terminal to print 9 instances of this loop. Any advice?

Okayā¦not sure where I went wrong but clearly the error was between keyboard and chairā¦I copied and pasted your code in and it worked like a charm. Iām lost as to what I did (I forgot to copy it down for comparison), but itās working now.

1 Like

For sure we will not want to print the squares object inside the loop. That would be left until weāre out of the loop.

``````print (squares)
``````

Now inside the loop we can still perform this on each iteration, but the value that is being appended, not the complete object.

``````for x in single_digits:
y = x ** 2
print (y)    # see below
squares.append(y)
``````

and then we donāt have to print the list afterwards, but it still exists for future reference.

Or,

``````    print (f"x: {x} => x ** 2: {y}")
``````
1 Like

I also believe it just gotten really complicated all of a sudden and had to use the hints to get through.
However I trust my friend which launched her career after 6 months of CodeAcademy. She went from zero to Business Scientist and got a job with Ā£60,000 per year from the beginning.
Itās definitely worth it. If the explanation is not clear enough, come in the forums and we will help. If this is not enough, go on Google or Youtube and I am sure you will find everything you need. This is the best course that explains as much as possible and you will not find a better step to step Platform that will get you through this.

Iām going to give up this course and not continue after the trial subscription precisely for these reasons. The material is so poorly explained and almost seems to have been written by a chatbot. Fully agree with whoever said it is like the first few lessons were well designed to get your subscription money and then everything goes downhill from there.

Hi there,

I was wondering if you could explain why ārangeā is acceptable for the square loop, but when used for the cubes loop it ācant call intā. I changed it to X and it worked no problem, thanks!

single_digits = range(10)

squares =

for range in single_digits:

print(range)

squares.append(range ** 2)

print(squares)

cubes = [range ** 3 for range in single_digits]

print(cubes)

Still studying the code, but must remark that it is never a good idea to use keywords or built-in function names as variable names. Is that what you changed to `x`?

1 Like

Thanks for the quick response! Yeah, I changed ārangeā for āxā. I had a feeling it had something to do with using the range function as the element.

1 Like

Honestly Iām starting to think that a lot of the explanations on codecadamy are extremely poorly written. If you go to stackoverflow and ask the problem the directions and answers are so much more clear.