def asBytes(obj):
 if isinstance(obj, list):
  return map(asBytes, obj)
 elif isinstance(obj, dict):
  return dict(((asBytes(k), asBytes(v)) for (k, v) in obj.items()))
 elif isinstance(obj, unicode):
  return obj.encode('utf-8')
 else:
  return obj

def asBytes ( obj ) : if isinstance ( obj , list ) : return map ( asBytes , obj ) elif isinstance ( obj , dict ) : return dict ( ( ( asBytes ( k ) , asBytes ( v ) ) for ( k , v ) in obj . items ( ) ) ) elif isinstance ( obj , unicode ) : return obj . encode ( 'utf-8' ) else : return obj
on python 2 .