refactor: Move constants outside of variable scope (#7262)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
Caeden
2022-10-16 10:33:29 +01:00
committed by GitHub
parent 7776411621
commit c6582b35bf
17 changed files with 107 additions and 97 deletions

View File

@ -1,3 +1,23 @@
BITS_TO_HEX = {
"0000": "0",
"0001": "1",
"0010": "2",
"0011": "3",
"0100": "4",
"0101": "5",
"0110": "6",
"0111": "7",
"1000": "8",
"1001": "9",
"1010": "a",
"1011": "b",
"1100": "c",
"1101": "d",
"1110": "e",
"1111": "f",
}
def bin_to_hexadecimal(binary_str: str) -> str:
"""
Converting a binary string into hexadecimal using Grouping Method
@ -17,25 +37,6 @@ def bin_to_hexadecimal(binary_str: str) -> str:
...
ValueError: Empty string was passed to the function
"""
BITS_TO_HEX = { # noqa: N806
"0000": "0",
"0001": "1",
"0010": "2",
"0011": "3",
"0100": "4",
"0101": "5",
"0110": "6",
"0111": "7",
"1000": "8",
"1001": "9",
"1010": "a",
"1011": "b",
"1100": "c",
"1101": "d",
"1110": "e",
"1111": "f",
}
# Sanitising parameter
binary_str = str(binary_str).strip()