Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

max/min function on list with strings and integers

I've got a list with strings and integers and want to find the minimum value of the integers, without list-slicing. Is there a work-around?

arr = [5,3,6,"-",3,"-",4,"-"]    
for i in range(len(set(arr))):
        cut = min(arr)

Many Thanks!

like image 851
semicolon Avatar asked Feb 15 '19 16:02

semicolon


1 Answers

You could filter the non numeric using a generator expression:

arr = [5,3,6,"-",3,"-",4,"-"]
result = min(e for e in arr if isinstance(e, int))
print(result)

Output

3
like image 150
Dani Mesejo Avatar answered Sep 28 '22 05:09

Dani Mesejo