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
Bryan Dobberstein
16,361 PointsA simplified version
As functions can be arguments to functions, I simplified s2v5.py thusly:
from s2v4 import *
def find_max_min(data_sample, col, func):
if func != max and func != min:
return 'Please set third argument to either "min" or "max"'
return func([float(row[2]) for row in data_sample])
if __name__=="__main__":
print(find_max_min(data_from_csv[1:], 2, max))
print(find_max_min(data_from_csv[1:], 2, min))
print(find_max_min(data_from_csv[1:], 2, len))
[MOD: added ``` python formatting -cf]
2 Answers
Chris Freeman
Treehouse Moderator 68,468 PointsInteresting improvement. Can I assume the third print using len is to test the if statement?
Also, it doesn't appear that the parameter col is used within the function. But I can see where the row[2] is used, so that's probably where you meant to use it.
Bryan Dobberstein
16,361 PointsYes the len tests the if. And the rowz[2] should indeed be row [col]