All pastes #113046 Raw Edit

TML

public text v1 · immutable
·published 2006-08-03 10:22 UTC
rendered paste body
def findKey(name, dicts, default=None):
    retval = default
    if (isinstance(dicts, list)) and (len(dicts) > 0):
        for d in dicts:
            retval = d.get(name, default)
    else:
        retval = dicts.get(name, default)
    return retval



baz = dict(bat=1)
def sample01(foo, bar=None):
    print findKey('bat', [baz], 1)
    print findKey('bar', [baz, locals()], 1)


sample01('foo')