我有一个我创建的列表:
range_list = range(1,len(sequence.split(" "))-1)
给出一个数字字符串序列:例如"1 2 2 6 1"
当我运行时:
if not range_list:
我收到语法错误(指向冒号)。这笔交易是什么?
编辑:
def jolly_jumper(sequence):
index = 1
range_list = range(1,len(sequence.split(" "))-1)
for num in sequence.split(" ")[:1]:
if(abs(int(num) - int(sequence.split(" ")[index])) > len(sequence.split(" ")) - 1 or abs(num - sequence.split(" ")[index]) == 0):
print "Not Jolly"
else:
filter(lambda a: a != abs(num - sequence.split(" ")[index], range_list)
if not range_list:
print "Jolly"
break
答案 0 :(得分:1)
您在此行中缺少)
:
filter(lambda a: a != abs(num - sequence.split(" ")[index], range_list)
应该是这样的:
filter(lambda a: a != abs(num - sequence.split(" ")[index]), range_list)