You are viewing a single comment's thread from:
RE: Payment for Coding done
Calculate the average price for each month
monthly_average_prices = {}
for flight in sorted_data:
year_month = flight["date"][:7] # Extract year and month (e.g., "2023-09")
if year_month not in monthly_average_prices:
monthly_average_prices[year_month] = {"total_price": 0, "count": 0}
monthly_average_prices[year_month]["total_price"] += flight["price"]
monthly_average_prices[year_month]["count"] += 1