I have a list L full of digits or strings, I want to find how many elements are different from a given one. So taking the list below, how would I figure find the elements that are not the digit 1 for example?
[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]
I'd use a conditional list comprehension to create a list without that element, and then check it's lenght:
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])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.