如何通过python列表项计算日期时间值

I have a python list that stores data for emails received and emails sent within same email thread. Emails received are marked as Email-In, and emails sent as Email-Out. Each Email-In or Email-Out has assigned specific requestID for the email thread and time stamp.

For example, for email thread with requestId = 735482556 there is incoming email on 15-May-2020 at 11:15:52:

[735482556, 'Email-In', '15-May-2020 11:15:52'] 

Values on my correspondence_list will change everyday and show data for different requestIDs as this script will scan my data daily.

My current correspondence_list:

[[735482556, 'Email-In', '15-May-2020 11:15:52'], [735482556, 'Email-Out', '15-May-2020 22:42:50'], [735482556, 'Email-In', '16-May-2020 11:58:41'], [735532797, 'Email-In', '16-May-2020 07:44:15'], [66789544, 'Email-In', '16-May-2020 10:44:15'], [66789544, 'Email-Out', '17-May-2020 11:44:15'], [66789544, 'Email-In', '17-May-2020 13:44:15'], [66789544, 'Email-Out', '17-May-2020 15:44:15'], [567432221, 'Email-In', '16-May-2020 20:30:15'], [567432221, 'Email-In', '16-May-2020 20:35:15'], [567432221, 'Email-Out', '16-May-2020 20:45:15']]

我要使用上面的列表来计算电子邮件输入和电子邮件输出的时间差,以便查看回复传入电子邮件需要多少时间。每个requestId可以有多封电子邮件进/出,具体取决于请求收到了多少回复。

So for example, requestId= 735482556 has 3 items. In this case I need to calculate the time difference between Email-In and Email-Out which is '11:26:58' and ignore the second 'Email-In' sent on '16-May-2020 11:58:41' as there is no Email-Out to pair it with.

 [735482556, 'Email-In', '15-May-2020 11:15:52'], [735482556, 'Email-Out', '15-May-2020 22:42:50'], [735482556, 'Email-In', '16-May-2020 11:58:41']

Desired output for my current correspondence_list:

 [[735482556, '11:26:58'], [735532797, 'not replied'], [66789544, '15:00:00', '02:15:00'],  [567432221, '0:15:00']

到目前为止,我的代码:

from datetime import datetime

s1 = '15-May-2020 11:15:52'
s2 = '15-May-2020 22:42:50' 
FMT = '%d-%b-%Y %H:%M:%S'
tdelta = datetime.strptime(s2, FMT) - datetime.strptime(s1, FMT)

def format_timedelta(tdelta):
    minutes, seconds = divmod(tdelta.seconds + tdelta.days * 86400, 60)
    hours, minutes = divmod(minutes, 60)
    return '{:d}:{:02d}:{:02d}'.format(hours, minutes, seconds)


myDifference = format_timedelta(tdelta)

上面的代码使我可以手动计算每个实例的时差。但是,我试图了解如何在列表中进行迭代,并在列表中进行计算,如果线程中没有电子邮件输入和电子邮件输出对,则忽略计算。有人可以帮忙吗?提前致谢!