question 156 Collections & Itertools · hard
Urgent deliveries go out in the wrong order
A webhook sender queues deliveries and sends one each time it gets a send event. Security alerts are urgent: every urgent delivery must go before every normal one, but urgent deliveries among themselves, and normal ones among themselves, must keep the order they were added. send_order jumps urgent deliveries to the front with appendleft, and when two urgent ones are waiting, they go out in reverse. Fix it.
Function
send_order(events)eventsa list of events:
["add", name, urgent] adds a delivery (urgent is True or False); ["send"] sends the next delivery, or does nothing if none is waitingReturnsthe names in the order they were sent
Keepthe function name and what it returns
Examples
callsend_order([['add', 'push-hook-1', False], ['add', 'alert-token-leak', True], ['add', 'alert-new-admin', True], ['send'], ['send'], ['send']])returns['alert-token-leak', 'alert-new-admin', 'push-hook-1']
callsend_order([['add', 'a', False], ['send'], ['add', 'b', True], ['add', 'c', False], ['send'], ['send']])returns['a', 'b', 'c']
callsend_order([['add', 'x', False], ['add', 'y', False]])returns[]