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

Using a list comprehension

I'm still having challenges usinng thhe list comprehension syntax where on my code should I change? Or rather I should just restart everything

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

good_temps = [temperature for temperature in map(c_to_f, temperatures) if temperature > 9 and temperature < 32.6]

1 Answer

Code challenge asks: "Convert each Celsius temperature into Fahrenheit, but only if the Celsius temperature is between 9 and 32.6."

But what you are doing is: "Convert each Celsius temperature into Fahrenheit, but keep the value only if the Fahrenheit temperature is between 9 and 32.6."

Hope it helps.

I get where you're coming from but now I don't know where to change

In plain english, you'll want to:

[execute the function on temperature, for each temperature in the list of temperatures, if the condition is met]

Or closer to python code:

[execute_the_function_on(temperature) for temperature in list_of_temperatures if condition_is_met]