code: def filter_tasks(
      tasks: Union[
          List[auto_scheduler.SearchTask], List[autotvm.task.Task]
      ],
      expr: str,
  ):
      """Utility to filter a list of tasks (AutoTVM or AutoScheduler) based on
      a user-supplied string expression.
  
      Parameters
      ----------
      tasks: list
          A list of extracted AutoTVM or AutoScheduler tasks.
      expr: str
          User-supplied expression to be used for filtering.
      """
      assert isinstance(
          expr, str
      ), "Expected filter expression of string type"
      assert len(expr) > 0, "Got empty filter expression"
  
      # groups of keywords are comma-separated
      splitted = expr.split(",")
  
      do_list = False
      do_filter = False
      selected = []
      for item in splitted:
          if item in ["list", "help"]:
              do_list = True
          elif item in ["all"]:
              selected = list(range(len(tasks)))
          else:
              do_filter = True
              if "-" in item:
                  assert (
                      item.count("-") == 1
                  ), "Malformed range expression"
                  assert (
                      len(item) > 1
                  ), "Missing lhs or rhs for range expression"
                  lhs, rhs = item.split("-")[:2]
                  lhs = int(lhs) if lhs else 0
                  rhs = int(rhs) if rhs else len(tasks) - 1
                  assert (
                      0 <= lhs < len(tasks)
                  ), "Left-hand side expression out of range"
                  assert (
                      0 <= rhs < len(tasks)
                  ), "Right-hand side expression out of range"
                  selected.extend(list(range(lhs, rhs + 1)))
              else:
                  assert isinstance(item, str)
                  idx = int(item)
                  assert (
                      0 <= idx < len(tasks)
                  ), "Task index out of range"
                  selected.append(idx)
  
      if do_filter:
          # remove duplicates
          selected = list(set(selected))
          tasks = [
              task for i, task in enumerate(tasks) if i in selected
          ]
  
      return tasks, do_list
  
imports: import os.path
  import logging
  import time
  from copy import deepcopy
  from typing import Any, Optional, Dict, List, Union
  from urllib.parse import urlparse
  import tvm
  from tvm import autotvm, auto_scheduler
  from tvm.auto_scheduler.search_task import HardwareParams
  from tvm.autotvm.tuner import GATuner
  from tvm.autotvm.tuner import GridSearchTuner
  from tvm.autotvm.tuner import RandomTuner
  from tvm.autotvm.tuner import XGBTuner
  from tvm.target import Target
  from .None import TVMCException, composite_target, frontends
  from .main import register_parser
  from .model import TVMCModel
  from .target import target_from_cli, generate_target_args, reconstruct_target_args
  from .shape_parser import parse_shape_string
  from .transform import generate_transform_args, parse_graph_transform_args, apply_graph_transforms
label_desc: Use image node_id 3 for calling a global function with example usage: filter_tasks(tasks, expr) and returns: tasks,  do_list