Skip to content
Advertisement

Group dates into list based on value

I have a json object that I’m trying to group item together in.

JavaScript

this code returns values grouped by date as the key and then a list of teams and dates like this

JavaScript

However, I need it to return and key value pair like this

JavaScript

where all the dates for a specific team are in a list as the value for the key Date.

Advertisement

Answer

This is one approach using dict.setdefault

Ex:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement