Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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]