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.
The input will be a single line containing space-separated integers.
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.
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
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')
Comments
Leave a comment