Home > Blockchain >  Find how many adjacent zeros in given list like this [100,1010,1001,1111,10100]
Find how many adjacent zeros in given list like this [100,1010,1001,1111,10100]

Time:03-02

I have tried this

list1=[100,1010,1001,1111,10100] Print(list1.count(00))

I got this

0

Expected Output:

3

CodePudding user response:

Did you try:

list1 = [100,1010,1001,1111,10100]
print("".join([str(x) for x in list1]).count("00"))

Prints: 3

CodePudding user response:

list.count(00) will only give you the number of occurrences of the value '00' in the list.
To look for the characters 00 within each list item you will need to iterate through the list and look at each item. Easiest check would be to convert the value to a string and then check for the double 00 characters within that

  • Related