Created
December 13, 2022 09:16
-
-
Save fenilgandhi/0145a257a3938a50f8c8bef6dbf8cbf6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
class IntHash(): | |
""" | |
Creates a runtime integer from a given list of integer, strings. | |
""" | |
@classmethod | |
def encode(self, list_value): | |
ascii_codes = [ord(_) for _ in json.dumps(list_value)] | |
result = "".join(map(str,ascii_codes)) | |
return int(result) | |
@classmethod | |
def decode(self, int_value): | |
int_value = str(int_value) | |
ascii_codes = [int_value[i:i+2] for i in range(0, len(int_value), 2)] | |
enc = "".join(map(lambda _:chr(int(_)), ascii_codes)) | |
return json.loads(enc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment