runtime
428 / 500
question 428 pandas Transformations · medium

Orders whose timeline is impossible

An order's timestamps must make sense: every timestamp that is present must be valid (YYYY-MM-DD HH:MM:SS), it can't ship before it was ordered, and it can't be delivered before it shipped. shipped_at and delivered_at may be None (not yet). Write timeline_problems(records): return the IDs of orders that break any rule, in their original order.

Functiontimeline_problems(records)
recordsdictionaries with order_id, ordered_at, shipped_at, delivered_at
Returnsa list of order IDs
Examples
calltimeline_problems([{'order_id': 'O100282', 'ordered_at': '2024-01-16 13:03:50', 'shipped_at': '2024-01-17 03:20:06', 'delivered_at': '2024-01-18 07:35:32'}, {'order_id': 'O999001', 'ordered_at': '2024-03-02 10:00:00', 'shipped_at': '2024-03-01 09:00:00', 'delivered_at': None}])returns['O999001']
calltimeline_problems([{'order_id': 'O103332', 'ordered_at': '2024-06-18 23:05:00', 'shipped_at': None, 'delivered_at': None}])returns[]
calltimeline_problems([])returns[]

Loading your progress…

Orders whose timeline is impossible — Python practice · Runtime