Write the
find_boundaries
function, which will take a list of numbers. The function should return the tuple with the smallest and largest number in the set. If there is an item in the list that is not a number, it should be ignored. If an empty list is entered, the function should returnNone
.
My code:
def find_boundaries(lista):
if not lista:
return None
elif lista:
max_ = lista[0]
min_ = lista[0]
new_lista = []
for i in lista:
if int == type(i):
new_lista.append(i)
for i in range(len(new_lista)):
if new_lista[i] > max_:
max_ = new_lista[i]
elif new_lista[i] < min_:
min_ = new_lista[i]
return max_, min_
I am looking for any opinion/ suggestion on that code. It does what is expected, but would you say that this is the most efficient way to solve that task in Python?