I am unable to perform a if conditional where a list is < 30. It returns an error everytime. I know this isn’t right but I’m not sure how to assign this to a variable within a list comprehension. Here is the question:
Carly thinks she can bring in more customers by advertising all of the haircuts she has that are under
30
dollars.Use a list comprehension to create a list calledcuts_under_30
that has the entryhairstyles[i]
for eachi
for whichnew_prices[i]
is less than30
.You can userange()
in your list comprehension to makei
go from0
tolen(new_prices) - 1
.
Here is my code:
cuts_under_30 = hairstyles[i] for i in range(len(new_prices - 1)) if new_prices < 30]