История изменений
Исправление Smola, (текущая версия) :
Python3
from collections import OrderedDict
map = OrderedDict((
(5, 0.1),
(10, 0.5),
(15, 0.7),
(20, 1.0),
(25, 1.25),
(30, 1.5),
#...
))
def val_to_res(val, map):
for breakpoint in map.keys():
if val <= breakpoint:
return map[breakpoint]
return 42.0
for val in range(50):
print(val, "->", val_to_res(val, map))
Исправление Smola, :
Python3
from collections import OrderedDict
map = OrderedDict((
(5, 0.1),
(10, 0.5),
(15, 0.7),
(20, 1.0),
(25, 1.25),
(30, 1.5),
#...
))
def val_to_res(val, map):
for breakpoint in map.keys():
if val <= breakpoint:
return map[breakpoint]
return 42.0
for val in range(50):
print(val, "->", val_to_res(val, map))
Исходная версия Smola, :
Python3
from collections import OrderedDict
map = OrderedDict((
(5, 0.1),
(10, 0.5),
(15, 0.7),
(20, 1.0),
(25, 1.25),
(30, 1.5),
#...
))
def val_to_res(val, map):
breakpoints = map.keys()
results = list(map.values())
for i, breakpoint in enumerate(breakpoints):
if val <= breakpoint:
return results[i]
return 42.0
for val in range(50):
print(val, "->", val_to_res(val, map))