+ 1
how to correctly convert words into numbers ?
how to correctly convert words into numbers ?
8 ответов
+ 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.
+ 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!
+ 2
Do you mean string to integer conversion? Or, e.g., "one" to 1?
+ 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?
+ 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.
+ 1
You can iterate on the string and pass character to the function ord("character") it will return a number
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
0
Int('word', 36)