#NEWLINE# def UpdateIterable( o , ki , value = None , default = None , op = None ) : #NEWLINE# #INDENT# "Update iteratable object 'o' at [Key or Index].\n\n  Args:\n    o: iterable object like list or dict\n    ki: key/index position to update\n    value: if defined, value to set at key/index\n    default: if defined, value to set if key/index does not yet exist,\n      otherwise no initialization is performed and operations on\n      non-existent keys or indexes raise KeyError/IndexError\n    op: if defined, a function to call with args (o[ki], value).\n      if the function returns a value other than None, that value\n      is used to update o[ki].  if None is returned, it is assumed\n      that the op function did something with the value and no further\n      operation is needed.\n  Returns:\n    None\n  Raises:\n    KeyError: if performing an op on a non-existent key without\n      default parameter used\n    IndexError: if performing an op on a non-existent or non-consecutive\n      index without default parameter used\n  " #NEWLINE# if ( ( default is not None ) and ( ki not in o ) ) : #NEWLINE# #INDENT# o [ ki ] = default #NEWLINE# #UNINDENT# if ( op is not None ) : #NEWLINE# #INDENT# new_v = op ( o [ ki ] , value ) #NEWLINE# if ( new_v is not None ) : #NEWLINE# #INDENT# value = new_v #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# value = None #NEWLINE# #UNINDENT# #UNINDENT# if ( value is not None ) : #NEWLINE# #INDENT# o [ ki ] = value