If you have a list of numbers, how do you return only the max odd integer without using the max() function?
I'm assuming it will have something to do with int % 2 != 0, but I'm not sure what else.
I also have to return the overall max integer without using max(), but I got around that by sorting my list and using list[-1].
max(i for i in my_list if i % 2)
Edit: without max():
def highest_odd(seq):
"""
Return the highest odd number in `seq`.
If there are no odd numbers, then return `None`.
"""
for i in sorted(seq, reverse=True):
if i % 2:
return i
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With