+ 1

how to correctly convert words into numbers ?

how to correctly convert words into numbers ?

15th Aug 2021, 12:10 PM
Alisa Zaiceva
8 Antworten
+ 4
Maintain a dictionary of words as key and value as numbers or vice versa. Iterate over the string and replace the word or number with key in the dictionary . The above is just a basic idea and might not work in many cases. If you need further help you can add the code(if you have written any) in description.
15th Aug 2021, 12:21 PM
Abhay
Abhay - avatar
+ 4
Alisa Zaiceva , it would help a lot if could prepare us some samples with inputs / words and the output you expect. also describe if the resulted number has to be translated back or whatever your total workflow will be. don't skip any steps. please also explain why you need to get the words to numbers. thanks!
15th Aug 2021, 8:03 PM
Lothar
Lothar - avatar
+ 2
Do you mean string to integer conversion? Or, e.g., "one" to 1?
15th Aug 2021, 12:18 PM
Lisa
Lisa - avatar
+ 1
this will not work quite correctly. for example, I have: a = 1, b = 2 ... L = 12... and I'm trying to translate the number 12 back. will the number 12 be equal to ab or L?
15th Aug 2021, 12:39 PM
Alisa Zaiceva
+ 1
the point is generally different for me. I want to teach the program to generate new characters for me through MO. to train it, I need both input and output data. the output is clear, these are the parameters strength dexterity and so on. but input is difficult for me. basically, I can use the id, name, creation date, and luck level. but I need to somehow turn this data into a number.
15th Aug 2021, 12:44 PM
Alisa Zaiceva
+ 1
You can iterate on the string and pass character to the function ord("character") it will return a number
15th Aug 2021, 1:19 PM
Honorable Con 🇸🇳
Honorable Con 🇸🇳 - avatar
0
You can just reverse the dictionary you made, keys are now values and vice versa. Then keep both dictionaries to swap values as needed. It's a bit frowned upon to have numbers as dictionary keys but for a translation of values like you want it may work
15th Aug 2021, 1:28 PM
Slick
Slick - avatar
0
Int('word', 36)
15th Aug 2021, 7:23 PM
Alisa Zaiceva