Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Functional Python Functional Workhorses Map and Filter Comprehension

list comprehension

As a dumb American, I don't understand Celsius temperatures. Using c_to_f and a list comprehension, create a variable named good_temps. Convert each Celsius temperature into Fahrenheit, but only if the Celsius temperature is between 9 and 32.6.

temps.py
temperatures = [
    37,
    0,
    25,
    100,
    13.2,
    29.9,
    18.6,
    32.8
]


def c_to_f(temp):
    """Returns Celsius temperature as Fahrenheit"""
    return temp * (9/5) + 32

def is_9_32_6(temp):
  return  (temp >= 9) and (temp <= 32.6)

good_temps = [is_9_32_6(temp) for temp in map(c_to_f, temperatures)]

1 Answer

Steven Parker
Steven Parker
229,645 Points

Close, but you're converting the temperatures first with map, and then using the list comprehension to return a true or false for each based on if the converted temperature is in the range.

But you want to return a converted temperature for each Celsius one that falls in the range.

Hint: you won't need a map.

And if you still can't get it...


:warning: SPOILER ALERT


good_temps = [c_to_f(temp) for temp in temperatures if is_9_32_6(temp)]

Great It works

Thank you