[英]How to count the number of times a digit appears at the beginning of each number in a file? (python)
[英]How would I determine the number of times a digit that is not Digit Y appears in a list
我有一个由数字或字符串组成的列表L,我想查找与给定元素不同的元素。 因此,以下面的列表为例,我将如何找到非数字1的元素?
[1,1,1,1,1,1,"hello",1,1,1,1,3,4,6,1,"world",1,1,1,1,3,4,3,"1",1,1,1,1,1,1,1,"welcome",3,4]
我将使用条件列表理解来创建没有该元素的列表,然后检查其长度:
l = [1,1,1,1,1,1,"hello",1,1,1,1,3,4,6,1,"world",1,1,1,1,3,4,3,"1",1,1,1,1,1,1,1,"welcome",3,4]
result = len([x for x in l if x != 1])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.