Skip to content
Advertisement

Get latest timestamp from list of dictionaries

I have list of dictionaries that I am pulling from a ticketing system. Each dictionary contains the name and timestamp of a ticket.

There are cases where multiple tickets are entered for the same user and I would like to filter this list to only append the ‘latest’ timestamp to the list, rather than all occurrences.

Edit: I am looking to get a list of dictionaries returned that includes a list of all unique Name values with the largest Date value.

I have included updated list examples that might make it easier to work with.

My function that gathers the data is:

JavaScript

My API call returns something that looks like this:

JavaScript

and would like it to look like this:

JavaScript

Advertisement

Answer

You can use itertools.groupby.

JavaScript

Output:

JavaScript

As an alternative, You can use .

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