Posts

How to Find A Missing Number in Python

When writing applications developers often come across scenarios where they need to solve a problem. That could be finding a specific word in a String , a property in an Object , an item/items in a list, and so on. Of the many possibilities you may need to find a number that is missing from a list of numbers. Sorted List First let us take a look at a sorted list. Since it is with integer numbers we'll have them sort from smallest to largest. For example: number_list = [1, 2, 4, 5, 6, 7, 8, 9, 10] As you can see we have a list ranging from 1 to 10 but missing the number 3. So now we need to figure out how to find it! Seems simple right? Well in a small case it is, but if we had a much larger list or we want to use the solution for different lists, then we will need to make an algorithm to find it. Loop Through the List Since we know that the list is sorted we can use a loop to iterate through every number in the list from 1 to 10. While doing this loop we can then check