w3resource logo

:

Python Exercises

Python Challenges: Find missing numbers from a list

Python Challenges - 1: Exercise-8 with Solution

Write a Python program to find missing numbers from a list.

Explanation:

Python: Find a missing numbers from a list

Sample Solution:-

Python Code:

def missing_numbers(num_list):
      original_list = [x for x in range(num_list[0], num_list[-1] + 1)]
      num_list = set(num_list)
      return (list(num_list ^ set(original_list)))

print(missing_numbers([1,2,3,4,6,7,10]))
print(missing_numbers([10,11,12,14,17]))

Sample Output:

[5, 8, 9]                                                                                                     
[13, 15, 16] 

Flowchart:

Python Flowchart: Find a missing numbers from a list

Python Code Editor:

Improve this sample solution and post your code through Disqus