Answers for "encode string to number python"

0

encoding character or string to integer in python

note:text contains your string or already read textfile 

import numpy as np
text = 'hello'
vocab=sorted(set(text))
char_to_ind = {char:ind for ind,char in enumerate(vocab)}
encoded_text = np.array([char_to_ind[c]for c in text])

your string has been encoded
Posted by: Guest on May-11-2020
1

convert string to number python

>>> x = "23"
>>> y = "20"
>>> z = int(x) - int(y)
>>> z
3
Posted by: Guest on March-13-2021

Code answers related to "encode string to number python"

Python Answers by Framework

Browse Popular Code Answers by Language