如何解决为什么这个功能没有按我的预期做?
我正在尝试以代码方式解决Lecture Sleep,但遇到了一个问题。这是我的代码:
n,k = map(int,input().split())
thereoms = list(input().split())
condition = list(input().split())
total = []
res = list((zip(thereoms,condition)))
combination = [[res[i],res[i + 1],res[i + 2]]
for i in range(len(res) - 2)]
for i in combination:
for num in i:
if num[1] == '1':
i.remove(num)
print(combination)
这是输入:
6 3
1 3 5 2 5 4
1 1 0 1 0 0
当我运行该程序时,输出如下:
[[('3','1'),('5','0')],[('5','0'),('4','0')]]
为什么要打印元素('3','1')
?即使我声明在element [1]等于1时删除所有元素?谁能帮我吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。