Answer to Question #191839 in Python for mani

Question #191839

Repeating & Non-Repeating Numbers


Given a list of numbers, find and print, the first number that occurs only once in the list and the first number that occurs more than once in the list.

Input


The input will be a single line containing space-separated integers.

Output


The first line of the output should contain the first non-repeating number. The second line of output should contain first repeating number. If there is no number fitting the given criteria, print "None" instead.

Explanation

For example, if the given list of integers are 5, 5, 4, 7, 4, 1, 11 , the first non-repeating number is 7 and the first repeating number is 5.


Sample Input 1

5 5 4 7 4 1 11


Sample Output 1

7

5


Sample Input 2

1 2 3 4 5 6 7 8 9


Sample Output 2

1

None




1
Expert's answer
2021-05-12T18:01:07-0400
numbers = [int(i) for i in input().split()]

values = {}
for i in numbers:
    if i in values:
        values[i] += 1
    else:
        values[i] = 1

pairs = [[k, v] for k, v in values.items()]

found = False
for pair in pairs:
    if pair[1] == 1:
        print(pair[0])
        found = True
        break
if not found:
    print('None')

found = False
for pair in pairs:
    if pair[1] > 1:
        print(pair[0])
        found = True
        break
if not found:
    print('None')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS