问题描述
我做了一个简单的程序。它将删除2个字符串中的几个不同的子字符串。
类似于Delete("hello","helloworld")
-> "hello"
。
然后,出现以下错误:
IndexError:从空列表中弹出
def Delete(s,t):
list_t=list(t)
list_s=list(s)
while list_t!=list_s:
list_t.pop()
#list_t.pop()
return "".join(list_t)
print(Delete("hello","helloworld"))
解决方法
您的问题是因为每次stat(ROPE[[1]] < x & x < ROPE[[2]])
迭代都调用ROPE <- rope_range(m_letters)
m_letters %>%
spread_draws(b_treatment,r_subject[subject,]) %>%
mutate(subject_estimate = b_treatment + r_subject) %>% #print()
ggplot(aes(y = subject,x = subject_estimate,fill = stat(ROPE[[1]] < x & x < ROPE[[2]]))) +
stat_slab()
两次。因此,在第三次迭代之后,您将拥有:
pop
这将导致无限循环,并因您尝试从空列表中while
元素而导致的错误而停止。删除list_t -> ['h','e','l','l']
list_s -> ['h','o']
之一,问题就解决了:
pop