0
有一个函数用于将字符串与列表中的项目进行匹配,该列表项目返回列表项目的索引编号是一场比赛。如下图所示:TypeError:在while循环中+:'NoneType'和'int'的不受支持的操作数类型
def get_int(get_wd, get_list):
for i, j in enumerate(get_list):
if j == get_wd:
get_i = i
return get_i
而且还有一个while循环中的主要功能从上面的函数获得返回整数
get_wd = []
x = 0
candi = []
while len(li_a) > 0:
iter_a = iter(li_a)
srh_time = len(li_a)
while srh_time > 0:
temp = next(iter_a)
if temp in li_words:
candi.append(temp)
else:
pass
srh_time = srh_time - 1
max_len = max(len(s) for s in candi)
extr_wd = list(set(s for s in candi if len(s) == max_len))
pos = get_int(extr_wd, li_a) ##Calling the function##
get_wd.append(extr_wd)
li_a = li_a[pos + 1:]
我收到此错误信息:
>> li_a = li_a[pos + 1:]
>> TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
对于我失踪的任何建议?
POS机不等于什么,你上面写的你的函数没有返回任何因此变量分配它为'NoneType'。你的原始函数中也不需要'get_i'。只要返回'我','如果j == get_wd:' –
我也曾尝试过,但仍然有相同的消息。 :( – htetmyet