Tuples and sets · 12 / 16 Exercise Medium

Guest lists

Objective

Create a Python program that compares the guest lists of two parties using set operations.

Instructions

  • Read two lines. Each one contains lower-case names separated by spaces.
  • Show three lines, with the names sorted alphabetically and separated by a space:
  • In both: the names that are in both lists (intersection).
  • Only in the first: those that are in the first and not in the second (difference).
  • In either: those that are in at least one of the two (union).
  • If a line has no names, show only the title followed by a colon, for example In both:.
Input
ana luis eva
luis eva marta
Output
In both: eva luis
Only in the first: ana
In either: ana eva luis marta

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise