+ 1

max value problem

I know i am missing something as the test fail but I am stuck on what I am missing https://code.sololearn.com/cctTifoTM92U

11th Mar 2019, 10:10 PM
Michael Harrall
Michael Harrall - avatar
4 ответов
+ 3
If input_list has no integers then [i for i in input_list if isinstance(i, int)] is an empty list. max([]) throws an error. You can fix it by doing something like this: a = max([i for i in input_list if isinstance(i, int)] or "_")
11th Mar 2019, 10:28 PM
Diego
Diego - avatar
+ 3
Michael Harrall I'm pretty sure there are other ways to fix your problem (ibra Kht just gave another solution). Using "or" seems the most simple to me.
11th Mar 2019, 10:37 PM
Diego
Diego - avatar
+ 1
@Diego thank you so much cant believe that was it just that dang or statement i had thought about that but was not sure what to go with.
11th Mar 2019, 10:35 PM
Michael Harrall
Michael Harrall - avatar
+ 1
In python max() function doesn't like Empty list, so in your code if the input_list doesn't have an integer value then you will get an error, thus you should check that the list is empty or not, then if it is not empty get its max value.
11th Mar 2019, 10:36 PM
ibra Kht
ibra Kht - avatar