Chris Angelico <ros...@gmail.com> writes: >> sentinel = object() >> seq = (dct.get('Keyword%d'%i,sentinel) for i in count(1)) >> lst = list(takewhile(lambda x: x != sentinel, seq)) > > If I understand this code correctly, that's creating generators, > right? It won't evaluate past the sentinel at all?
Right, it should stop after hitting the sentinel once. > That might well be what I'm looking for. A bit ugly, but efficient and > compact. And I can bury some of the ugliness away. It occurs to me, operator.ne might be a little faster than the interpreted lambda. -- http://mail.python.org/mailman/listinfo/python-list