on-internet
← Community

Getting the first non None value from list

Stack Overflow ·

Given a list, is there a way to get the first non-None value? And, if so, what would be the pythonic way to do so? For example, I have: a = objA.addreses.country.code b = objB.country.code c = None d = 'CA' In this case, if a is None, then I would like to get b. If a and b are both None, the I would like to get d. Currently I am doing something along the lines of (((a or b) or c) or d), is there another way?

Comments

Sign in or sign up to comment and upvote.

No comments yet.