36-650-Fall-2020 / fp-unit-test-assignment-YixuanLuo98

fp-unit-test-assignment-YixuanLuo98 created by GitHub Classroom
1 stars 0 forks source link

avoid duplicate code #5

Open alexazhu opened 3 years ago

alexazhu commented 3 years ago

for line 19-25 in function.py, I think they can be merged into one function since they have the same value forsub; maybe set "death" or "cases" as input to call for reduce function. In this way, we can save the lines for cumm_deaths

def cumm_cases(data, start_date, end_date): sub = data.loc[(data["date"] >= start_date) & (data["date"] <= end_date)] return reduce(lambda x,y: x+y, sub["cases"] def cumm_deaths(data, start_date, end_date): sub = data.loc[(data["date"] >= start_date) & (data["date"] <= end_date)] return reduce(lambda x,y: x+y, sub["deaths"])

Thanks ;)

YixuanLuo98 commented 3 years ago

Good catch! I was thinking maybe I'll create another index to store "deaths" or "cases", or maybe both! This way I'll replace the sub["cases"] or sub["deaths"] by sub[index] and merge these two functions into one! Or I can make the output a list of result = (cases, deaths) and do result[0] and result[1] to select the proper value.