Feb. 22, 2014
5:38 a.m.
On Sat, Feb 22, 2014 at 4:14 PM, Eric Snow <ericsnowcurrently@gmail.com> wrote:
def getitem(seq, index, default=_NOT_SET): try: return seq[index] except IndexError: if default is _NOT_SET: raise return default
Of course, one might expect getitem() to work for mappings too (or we'd have 2 distinct functions for mappings and sequences). Having getitem() work for both would not be too hard.
Very easy. Just catch LookupError or (IndexError, KeyError) instead of IndexError. ChrisA