🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Closures and Warshall's Algorithm: all 10 questions

Quiz: Closures and Warshall's Algorithm · Question 4 of 10

What does this print? (code)

What does this print?

R = {(1, 2), (2, 3), (3, 1)}
RR = {(a, c) for (a, b) in R for (b2, c) in R if b == b2}
print(sorted(RR))
  1. A.[(1, 2), (2, 3), (3, 1)]
  2. B.[(1, 3), (2, 1), (3, 2)]
  3. C.[(1, 1), (2, 2), (3, 3)]
  4. D.[]
Answer & explanation

Correct answer: [(1, 3), (2, 1), (3, 2)]

R∘R joins two steps: 1→2→3, 2→3→1 and 3→1→2.

Can you get the rest right without peeking?

Take the timed Quiz: Closures and Warshall's Algorithm quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →