Here are some tests:
Input: "zero nine five two"
Output: "four"
Input: "four six two three"
Ouput: "three"
Here is my code, which works until the last step where I need to inverse lookup key by value, which I dont know how to do. Any advice?
def average_string(s):
num_dic = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5,
'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}
str_split = s.split()
int_values = []
for key, val in num_dic.items():
if key in str_split:
int_values.append(val)
int_avg = int(sum(int_values) / len(int_values))
return int_avg