I'd like to accept either one dict or a list of dicts as a function argument. So far, I've come up with the following, but I suspect I've missed something completely obvious, and am using something fragile (isinstance
):
def wrap(f):
def enc(inp):
if isinstance(inp, list):
for item in inp:
f(item)
else:
f(inp)
return enc
@wrap
def prt(arg):
# do something with the dict
print arg.keys()