I am trying to mess around with lambda functions in regards to lists, and i am wondering whether it is possible to optimize this code:
print(max([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], key=lambda x: x if x<9 else 0))
This code-snip does indeed work, but i wonder whether there is a way to remove the else-part in the lambda function itself, as this seems to be a necessary "parameter". I am very well aware that i could just use a list comprehension like [i for i in arr if i<9], but i am looking for solutions to this specific function.
I am using Python 3.10.6.
I have tried several ways to rewrite the lambda function, but i keep getting the error that i need the else-part.