livepython.net

206. Python Program to Find the Numbers That Appear More Than Once

MediumPhase 2 · Practice

It takes a few steps, but every tool is one you know: split(), count() and not in.

Overview

Finding the repeats in a list is a common interview question. A shop does the same to find an order that was typed twice.

Problem Statement

Chen checks the seat numbers sold for a school show. Each seat should be sold only once, so a number that appears more than once is a problem.

  • Print each repeated number only once, even if it appears three or more times.
  • Print the numbers in the order they first appear in the list.
  • Print Repeated: <numbers>, with one space between the numbers.
  • If no number appears more than once, print No repeated numbers.

Examples

Example 1. Input 3 1 1 3 4 gives:

Repeated: 3 1

Why: 3 and 1 both appear twice. 3 is the first number in the list, so it is printed first.

Example 2. Input 4 7 2 gives:

No repeated numbers

Why: each number appears only once.

Input

One line of whole numbers, with one space between them (1 number or more). Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Output

One line: Repeated: <numbers> or No repeated numbers. The tests try 7 different inputs, also a number that appears more than twice.

Try it first. The solution opens when you solve this question, or after 3 tries with Submit.

Finish this chapter firstChapter 12 · Working With Strings
solution.py
# write your code here

EXPECTED OUTPUT

1Repeated: 3 1

YOUR OUTPUT

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