livepython.net

126. Python Program to Find Common Friends Using Sets

MediumSets

Overview

Who do two people both know? That's the intersection of two sets.

Problem Statement

Read two lines. Each line is one person's friends: names separated by spaces. Print the names that are on both lines, in A to Z order, joined with a comma and a space, then how many there are. For example, for Sunny Rocky Lucky Tom and Tom Lucky Ana Rocky:

Common friends: Lucky, Rocky, Tom
Count: 3

If no name is on both lines, print only:

No common friends

A name may appear more than once on a line; count it once.

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

Two lines of names. Example:

Sunny Rocky Lucky Tom
Tom Lucky Ana Rocky

Output

The output for that example:

Common friends: Lucky, Rocky, Tom
Count: 3

The tests try 3 different inputs.

Learn this firstChapter 14 · Python Sets: Unique Items, add(), remove() and in
solution.py
# write your code here

EXPECTED OUTPUT

1Common friends: Lucky, Rocky, Tom
2Count: 3

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.