The nearest integers not in the list?

0 like 0 dislike
5 views
There is a list with the variables in which are recorded not integers.
[2.991026919242273, 0.4985044865403789, 4.885343968095713, 2.4925224327018944, 0.19940179461615154, 2.193419740777667, 4.586241276171486, 9.970089730807578, 23.230309072781655, 2.8913260219341974, 1.7946161515453638, 4.287138584247258, 17.547357926221338, 0.3988035892323031, 1.3958125623130608, 0.29910269192422734, 6.580259222333001, 5.18444666001994, 1.296111665004985, 3.8883349950149553, 2.7916251246261217, 0.7976071784646062, 7.676969092721834, 1.5952143569292123, 6.181455633100698, 2.293120638085743, 2.691924227318046, 4.087736789631107, 0.0, 0.09970089730807577, 2.293120638085743, 1.9940179461615155, 11.266201395812562]

In the list of recorded prevalence of each of the letters of the Russian language in a text.
I have a template of probability, something like "the Letter is found somewhere in the 10% then this letter can be "about".
("Template probability" is also recorded in the list)
The problem:
I have a number - the percentage of a specific letter in the text, and I need to find the closest value from the list "template probability". And after you replace the letter in the initial text on the basis of which the likelihood of occurrence of the text entered. How to do it? *Find the closest number from a list to a certain number and replace the letter in the text according to the probability which is left(the prevalence of a specific letter)*
by | 5 views

2 Answers

0 like 0 dislike
values = [2.991026919242273, 0.4985044865403789, 4.885343968095713, 2.4925224327018944, 0.19940179461615154, 2.193419740777667, 4.586241276171486, 9.970089730807578, 23.230309072781655, 2.8913260219341974, 1.7946161515453638, 4.287138584247258, 17.547357926221338, 0.3988035892323031, 1.3958125623130608, 0.29910269192422734, 6.580259222333001, 5.18444666001994, 1.296111665004985, 3.8883349950149553, 2.7916251246261217, 0.7976071784646062, 7.676969092721834, 1.5952143569292123, 6.181455633100698, 2.293120638085743, 2.691924227318046, 4.087736789631107, 0.0, 0.09970089730807577, 2.293120638085743, 1.9940179461615155, 11.266201395812562] my_probability = 5.0 result = min(values, key=lambda x:abs(x-my_probability))

Python3
by
0 like 0 dislike
And why is it considered difficult?

Your source list, call freqs, the value that you substitute z, then:

z = ... distances = list(map(lambda x: abs(x-z), freqs)) nearestIndex = distances.index(min(distances))
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
asked Apr 21, 2019 by NogerbekNurzhan
0 like 0 dislike
3 answers
110,608 questions
257,186 answers
0 comments
33,932 users