🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Distributed Transactions and Sagas: all 10 questions

Quiz: Distributed Transactions and Sagas · Question 4 of 10

What does this print? (code)

What does this print?

done = ["charge", "accept"]
undo = {"charge": "refund", "accept": "cancel"}
print([undo[s] for s in reversed(done)])
  1. A.['refund', 'cancel']
  2. B.['cancel', 'refund']
  3. C.['charge', 'accept']
  4. D.['accept', 'charge']
Answer & explanation

Correct answer: ['cancel', 'refund']

Compensations run in reverse order: undo the latest completed step first.

Can you get the rest right without peeking?

Take the timed Quiz: Distributed Transactions and Sagas quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →