我在处理这个错误不支持的操作数类型错误时遇到了麻烦,我不确定在这种情况下我做错了什么。任何帮助,将不胜感激!!
def closest_pair(list):
if (len(list) <= 3):
return min_distance(list)
else:
left, right = split_into_two(list)
left_min = closest_pair(left)
right_min = closest_pair(right)
if(left_min[2]>right_min[2]):
return right_min
else:
return left_min
def split_into_two(list):
med_val = statistics.median(list)
med_x = med_val[0]
left = []
right = []
for i in list:
if (i[0]<med_x):
left.append(i)
else:
right.append(i)
return left, right
和打印最接近的对给出:
Traceback (most recent call last):
File, line 109, in <module>
print(closest_pair(text_file))
File, line 61, in closest_pair
left_min = closest_pair(left)
File, line 62, in closest_pair
right_min = closest_pair(right)
File, line 60, in closest_pair
left, right = split_into_two(list)
File, line 44, in split_into_two
med_val = statistics.median(list)
File, line 358, in median
return (data[i - 1] + data[i])/2
TypeError: unsupported operand type(s) for /: 'tuple' and 'int'