1
0
mirror of https://github.com/altlinux/gpupdate.git synced 2025-03-21 18:50:38 +03:00

Added function remove_prefix_from_keys in util

This commit is contained in:
Valery Sinelnikov 2025-02-06 14:25:48 +04:00
parent 25a784fa2e
commit a77a6e3c6f

View File

@ -221,6 +221,13 @@ def remove_keys_with_prefix(dictionary: dict, prefix: tuple=('Previous/', 'Sourc
"""
return {key: value for key, value in dictionary.items() if not key.startswith(prefix)}
def remove_prefix_from_keys(dictionary: dict, prefix: str) -> dict:
"""
Removes the specified prefix from the keys of the dictionary.
If a key starts with the prefix, it is removed.
"""
return {key[len(prefix):] if key.startswith(prefix) else key: value for key, value in dictionary.items()}
def get_trans_table():
return str.maketrans({