You really want to display example.get in sequence and get the first true value. To do this, you can use filter with a default filter function that does just that, and get the first one with next :
>>> example = {'answer': 42, 'bring': 'towel'} >>> lst = ['dolphin', 'guide', 'answer', 'panic', 'bring'] >>> next(filter(None, map(example.get, lst))) 42
In Python 3, all these things are lazy, so the whole sequence is not repeated. In Python 2, you can use itertools to get lazy versions of the built-in functions, imap and ifilter
source share