The top code is mine, the bottom code is the given solution.
can_ride_coaster = [ height > 161 for height in heights]
can_ride_coaster = [height for height in heights if height > 161]
Why does my code print out True False? What would make it print out the true integers?
Also to me "height for height in heights " seems clunky. Why is that the correct phrasing ?
height > 161 is a conditional that’s
[ height > 161 for height in heights]
will create a list that filled with elements that are
Each element in the list heights is temporarily stored as height (one at a time), and the result of comparing this value to 161 is stored in a new list.
In the solution,
if height > 161 limits the values that are stored as
height to only the elements in the
heights list greater than 161.
height for height just means to use exactly what
height is for the new list without any changes.
It may be easier to read if a different word was used
[value for value in heights if value > 161]
but it still doesn’t sound like English.
Thanks for response. That helped