I have a list of dictionaries (message threads), that contain another list of dictionaries (messages) I need to order the threads by the date of the most current message.
what the data looks like
[
{key:thread1,
messages:[
{key:message1,
date:10/10/2023
}
/// older messages
]
},
{key:thread2,
messages: [
{key:message4,
date:10/13/2023
},
///older messages
]
}
]
I need to sort it so that the first in the list would be thread 2 which has the most recent message as appose to thread1, the messages are already correctly sorted already.
Approach
Create a function that use Python sorted function to sort list with a key function and in reverse order
Code
Usage
Output
Result is thread2 is first