Python Challenges: Find the single number in a list that doesn't occur twice
Python Challenges - 1: Exercise-12 with Solution
Write a Python program to find the single number in a list that doesn't occur twice.
Explanation:
Sample Solution:
Python Code:
def single_number(arr):
result = 0
for i in arr:
result ^= i
return result
arr1 = [5, 3, 4, 3, 4]
arr2 = [3, 2, 5, 2, 1, 5, 3]
print(single_number(arr1))
print(single_number(arr2))
Sample Output:
5 1
Flowchart:
Python Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Python program to compute and return the square root of a given 'integer'.
Next: Write a Python program to find the single element in a list where every element appears three times except for one.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://198.211.115.131/python-exercises/challenges/1/python-challenges-1-exercise-12.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics