from typing import Dict
import functools


def DictToArgs(d: Dict[str, str]):
  """Converts the dictionary `d` to list of arguments for `subprocess.Popen()`.

  For each (k, v) pair in the dictionary, two entries are added to the list:
  "--k" and "v". So {"sport": "hockey", "goals": 7} is converted to: ["--sport",
  "hockey", "--goals", "7"].

  Note that all keys must be strings. All values are converted to a string
  regardless of their type.

  Args:
    d: The dictionary to convert to a list.

  Returns:
    The list of arguments for `subprocess.Popen()`, generated from `d`.
  """
  return functools.reduce(lambda a, key: a + ["--" + key, d[key]], d, [])