code: def parse_resources(resources_args, fallback=None):
      """Parse resources from args."""
      resources = dict()
  
      if resources_args is not None:
          valid = re.compile(r"[a-zA-Z_]\w*$")
  
          if isinstance(resources_args, list):
              resources_args = map(
                  DefaultResources.decode_arg, resources_args
              )
          else:
              resources_args = resources_args.items()
  
          for res, val in resources_args:
              if not valid.match(res):
                  raise ValueError(
                      "Resource definition must start with a valid identifier, but found "
                      "{}.".format(res)
                  )
  
              try:
                  val = int(val)
              except ValueError:
                  if fallback is not None:
                      val = fallback(val)
                  else:
                      raise ValueError(
                          "Resource definiton must contain an integer, string or python expression after the identifier."
                      )
              if res == "_cores":
                  raise ValueError(
                      "Resource _cores is already defined internally. Use a different "
                      "name."
                  )
              resources[res] = val
      return resources
  
imports: from collections import UserDict, defaultdict
  import itertools
  import operator
  import re
  import tempfile
  from snakemake.exceptions import ResourceScopesException, WorkflowError
  from snakemake.common.tbdstring import TBDString
label_desc: Use image node_id 2 for calling a global function with example usage: parse_resources(resources_args, fallback) and returns: resources