I have a list of dictionaries as such that has source_id
and timestamps
:
[{'source_id': 'RECEIVE',
'event_lcl_ts': Timestamp('2024-04-14 02:17:14.905000')},
{'source_id': 'MOVEMENT', 'event_lcl_ts': Timestamp('2024-04-14 03:43:27.288000')},
{'source_id': 'PUTAWAY',
'event_lcl_ts': Timestamp('2024-04-14 03:48:11.549000')},
{'source_id': 'PICK',
'event_lcl_ts': Timestamp('2024-04-14 07:56:31.460000')},
{'source_id': 'PACK',
'event_lcl_ts': Timestamp('2024-04-14 11:27:02.125000')},
{'source_id': 'RECEIVE',
'event_lcl_ts': Timestamp('2024-04-14 23:43:37.658000')},
{'source_id': 'MOVEMENT', 'event_lcl_ts': Timestamp('2024-04-15 01:05:58.008000')},
{'source_id': 'PUTAWAY',
'event_lcl_ts': Timestamp('2024-04-15 02:31:20.452000')}
]
I would like to collect information starting with the source_id == 'RECEIVE'
and end with the source_id == 'PUTAWAY'
and ignore the other source_ids
.
This is just a sample and there are many different source_id
so I think ideally using a while loop starting with the RECEIVE
and ending it on PUTAWAY
would be the best way to do this. What is the best way to loop through a list of dictionaries and collect information between two values and ignore the others?
My ideal output for this would be a list of tuples that is
[[("RECEIVE", '2024-04-14 02:17:14.905000'),
("MOVEMENT", '2024-04-14 03:43:27.288000'),
("PUTAWAY", '2024-04-14 03:48:11.549000')],
[("RECEIVE", '2024-04-14 23:43:37.658000'),
("MOVEMENT", '2024-04-15 01:05:58.008000'),
("PUTAWAY", '2024-04-15 02:31:20.452000')]]
Thanks!