def ensure_arg(args, arg, param=None):
 found = False
 for (idx, found_arg) in enumerate(args):
  if (found_arg == arg):
   if (param is not None):
    args[(idx + 1)] = param
   return args
 if (not found):
  args += [arg]
  if (param is not None):
   args += [param]
 return args

def ensure_arg ( args , arg , param = None ) : found = False for ( idx , found_arg ) in enumerate ( args ) : if ( found_arg == arg ) : if ( param is not None ) : args [ ( idx + 1 ) ] = param return args if ( not found ) : args += [ arg ] if ( param is not None ) : args += [ param ] return args
make sure the arg is present in the list of args .