(dictionary: Mapping[Text, Any],
                            prefix: Text,
                            keep_prefixes: Optional[Set[Text]] = None)
return new_dictionary
Strips a prefix from dictionary keys and remove keys without the prefix.

  Strips a prefix from the keys of a dictionary and removes any key from the
  result dictionary that doesn't match the determined prefix, unless explicitly
  excluded in keep_prefixes.

  E.g.
  dictionary={
    'example_key': 1,
    'example_another_key': 2,
    'doesnt_match': 3,
    'keep_this': 4,
  }, prefix='example_', keep_prefixes=['keep_']

  would return
  {
    'key': 1,
    'another_key': 2,
    'keep_this': 4,
  }

  Args:
    dictionary: The dictionary whose keys will be stripped.
    prefix: The prefix to strip.
    keep_prefixes: Optionally specify prefixes for keys that will be unchanged
      and retained in the result dictionary.

  Returns:
    The dictionary with the modified keys and original values (and unchanged
    keys specified by keep_prefixes).
Strips a prefix from dictionary keys and remove keys without the prefix.
Strips a prefix from dictionary keys and remove keys without the prefix .
def _strip_reference_prefix(dictionary: Mapping[Text, Any],
                            prefix: Text,
                            keep_prefixes: Optional[Set[Text]] = None):
  """Strips a prefix from dictionary keys and remove keys without the prefix.

  Strips a prefix from the keys of a dictionary and removes any key from the
  result dictionary that doesn't match the determined prefix, unless explicitly
  excluded in keep_prefixes.

  E.g.
  dictionary={
    'example_key': 1,
    'example_another_key': 2,
    'doesnt_match': 3,
    'keep_this': 4,
  }, prefix='example_', keep_prefixes=['keep_']

  would return
  {
    'key': 1,
    'another_key': 2,
    'keep_this': 4,
  }

  Args:
    dictionary: The dictionary whose keys will be stripped.
    prefix: The prefix to strip.
    keep_prefixes: Optionally specify prefixes for keys that will be unchanged
      and retained in the result dictionary.

  Returns:
    The dictionary with the modified keys and original values (and unchanged
    keys specified by keep_prefixes).
  """
  keep_prefixes = keep_prefixes or []
  new_dictionary = dict()
  for key in dictionary:
    if key.startswith(prefix):
      key_without_prefix = key.split(prefix)[1]
      # note that this will not copy the underlying array.
      new_dictionary[key_without_prefix] = dictionary[key]
    else:
      for keep_prefix in keep_prefixes:
        if key.startswith(keep_prefix):
          new_dictionary[key] = dictionary[key]

  return new_dictionary
def _strip_reference_prefix ( dictionary : Mapping [ Text , Any ] , prefix : Text , keep_prefixes : Optional [ Set [ Text ] ] = None ) : keep_prefixes = keep_prefixes or [ ] new_dictionary = dict ( ) for key in dictionary : if key . startswith ( prefix ) : key_without_prefix = key . split ( prefix ) [ 1 ] # note that this will not copy the underlying array. new_dictionary [ key_without_prefix ] = dictionary [ key ] else : for keep_prefix in keep_prefixes : if key . startswith ( keep_prefix ) : new_dictionary [ key ] = dictionary [ key ] return new_dictionary