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

Found a better way of defining max_min function

Hey Kat,

First off: I love this course, I would love to see more of data science in the future. This is actually why I'm learning programming. And I really like how you teach.

Second, I think I have a better way of handling the min_max function:

#Max & Min
def find_max_min(data_sample, col=2):
    temp_list = list()
    for row in data_sample:
        temp_list.append(float(row[col]))
    return max(temp_list),min(temp_list)

and then catch the result in a tuple:

(max_price, min_price) = find_max_min(data_from_csv[1:])

you'll be creating a variable for each returned value from the function.

1 Answer

Good idea, assuming you always want both the maximum and the minimum...

You could also just have a function that fetches the values in one column of the data sample and returns it as a list of floats. Then you would use Python's built-in functions to get the average, max, min, etc.