I'm sure there's a simpler way of doing this that's just not occurring to me.
I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:
my_list = get_list()
if len(my_list) > 0: return my_list[0]
return None
It seems to me that there should be a simple one-line idiom for doing this, but for the life of me, I can't think of it. Is there?