def default_iget(fields,default=None,):
    """ itemgetter with 'default' handling, that *always* returns lists

    API CHANGES from ``operator.itemgetter``

    Note: Sorry to break the iget api... (fields vs *fields)
    Note: *always* returns a list... unlike itemgetter,
        which can return tuples or 'singles'
    """
    myiget = operator.itemgetter(*fields)
    L = len(fields)
    def f(thing):
        try:
            ans = list(myiget(thing))
            if L < 2:
                ans = [ans,]
            return ans
        except KeyError:
            # slower!
            return [thing.get(x,default) for x in fields]

    f.__doc__ = "itemgetter with default %r for fields %r" %(default,fields)
    f.__name__ = "default_itemgetter"
    return f
dataset/ETHPy150Open pydata/pandas/scripts/json_manip.py/default_iget/original