Answers for "encoding int to chr in python and vice versa"

0

encoding int to chr in python and vice versa

# encode the text and map each character to an integer and vice versa

# we create two dictionaries:
# 1. int2char, which maps integers to characters
# 2. char2int, which maps characters to unique integers
chars = tuple(set(text))
int2char = {ind:char for ind,char in enumerate(chars)}
char2int = {char:ind for ind,char in enumerate(chars)}

# encode the text
encoded = np.array([char2int[ch] for ch in text])
Posted by: Guest on October-04-2021

Code answers related to "encoding int to chr in python and vice versa"

Python Answers by Framework

Browse Popular Code Answers by Language