In this example, we will create a python function which will take in a list of numbers and then return the smallest value. The solution to this problem is first to create a place holder for the first number within the list, then compares that number with other numbers within the same list in the loop. If the program found a number which is smaller than the one in the place holder, then the smaller number will be assigned to that place holder.
def find_smallest_int(arr): smallest = None for elem in arr: if(smallest == None or smallest > elem): smallest = elem return smallest
If you have a better solution then kindly leave your comment below this post.