How to Find the Lowest Number in the Python List

Method 1

min = float('inf')
l = [1,2,4,6,8,0.2,5]
for temp in l:
    if min >float(temp):
     min = float(temp)
     
print(min)

Method 2

l = [1,2,4,6,8,0.2,5]
print min(l)

Execution time test

import re
import timeit


def method_1():
    minNumber = float('inf')
    l = [1, 2, 4, 6, 8, 0.2, 5]
    for temp in l:
        if minNumber > float(temp):
            minNumber = float(temp)

    return minNumber


def method_2():
    l = [1, 2, 4, 6, 8, 0.2, 5]
    return min(l)


def main():
    time = timeit.repeat(lambda: method_1())
    print("Method 1 time - ", time)
    time = timeit.repeat(lambda: method_2())
    print("Method 2 time - ", time)


if __name__ == "__main__":
    main()

Result

Method 1 time -  [1.5683278, 1.5621189000000002, 1.7238973999999998, 1.5738824000000005, 1.5778435999999996]
Method 2 time -  [0.4773139000000004, 0.4864171000000006, 0.5115584999999996, 0.6321463000000005, 0.5445452]

You can see that method 2 (min(l)) is the fastest.