← 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))
- A.[(1, 2), (2, 3), (3, 1)]
- B.[(1, 3), (2, 1), (3, 2)]
- C.[(1, 1), (2, 2), (3, 3)]
- 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 →