![](/img/trans.png)
[英]invalid literal with int base 10 for only one input in list, when all others work (postfix)
[英]How to check if only one position in a list is blank and all others are not
我有一个清单
list = [' ' for x in range(10)]
如果我向这个列表添加值,我如何检查只有 list[0] 为空而 list[1] - list[9] 不是?
假设l
是包含值的列表,您可以执行以下操作:
if l[0] == ' ' and all(s != ' ' for s in l[1:9]):
print("Complete!!!!!!")
你可以使用all
list1=[' ' if i==0 else i for i in range(10) ]
if list1[0]==" " and all(x!=' ' for x in list1[1:9]):
print("Complete List!!!")
最简单、最直接的方法是通过每个元素向 go 编写一个循环。 跟踪元素是什么,然后用这些信息做一些事情。
一种让您知道恒定时间的方法是跟踪您更改了多少不同的索引,然后只检查剩下多少空白空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.