code: def pick_kwargs(kwargs: dict, required_args: list, prefix: str = None):
      picked = {k: v for k, v in kwargs.items() if k in required_args}
      prefixed = {}
      if prefix:
          prefix = prefix + '__'
          prefixed = {
              _remove_prefix(k, prefix): v
              for k, v in kwargs.items()
              if k.startswith(prefix)
              and _remove_prefix(k, prefix) in required_args
          }
      conflicting_args = [k for k in picked if k in prefixed]
      if conflicting_args:
          raise ValueError(
              'Both prefixed and unprefixed args were specified '
              'for the following parameters: {}'.format(conflicting_args)
          )
      return tz.merge(picked, prefixed)