Why isn't this valid?

Hi, why isn’t this a valid solution?

#Write your function here
def max_num(nums):
maximum = nums[0]
maximum = [num for num in nums if num > maximum]
maximum = maximum[0]
return maximum

#Uncomment the line below when your function is done
print(max_num([50, -10, 0, 75, 20]))

maximum = [num for num in nums if num > maximum]

I assume this might be the reason, if your num is smaller than the value previously assign to maximum, then your maximum value won’t keep updating.
you can validate by insert a number < 50 in the first place of the list(before 50), or change 0 in the list to 60, and you’ll get a result 60 instead of 75 it should be.

[1, 50, -10, 0, 75, 20] ==> result 50
[49, 50, -10, 0, 75, 20] ==> result 50
[50, -10, 60, 75, 20] ==> result 60

Ah ok I see where you’re coming from. Well in that case I passed the exercise by simply returning maximum[0], and shouldn’t have :sweat_smile:.