max/min function on list with strings and integers

  • A+
Category:Languages

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!

 


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 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: