Answer to Question #188629 in Python for phani

Question #188629
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-03T12:20:29-0400
def repeat_no_repeat(s):


	n = s.split()
	first_repeat = None
	no_repeat = None
	for i in range(len(n)):
		if not first_repeat and n[i] in n[i+1:]:
			first_repeat = n[i]
		if not no_repeat and not (n[i] in n[:i]+n[i+1:]):
			no_repeat = n[i]
	print(no_repeat)
	print(first_repeat)


while True:
	test = input('enter space-separated integers or -999 to exit\n')
	if test == '-999':
		break
	repeat_no_repeat(test)

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
APPROVED BY CLIENTS