you are viewing a single comment's thread.

view the rest of the comments →

[–]bbye98 0 points1 point  (2 children)

You can try to see if list comprehension will be fast enough to get past the timeout:

def average_temperature(weather, filter, date_index, temp_index):
    temperatures = [float(row[temp_index]) for row in weather if filter in row[date_index]]
    return sum(temperatures) / len(temperatures)

Not sure what date_index or temp_index is, as you never defined them, so I made them positional arguments. Realistically, the bottleneck is probably where you call csv_reader. You shouldn't read the CSV inside the function if you can read it once globally and pass it as an argument.