Count consecutive characters

后端 未结 9 1618
别那么骄傲
别那么骄傲 2020-11-28 06:44

How would I count consecutive characters in Python to see the number of times each unique digit repeats before the next unique digit?

At first, I thought I could do

9条回答
  •  情书的邮戳
    2020-11-28 07:17

    This is my simple code for finding maximum number of consecutive 1's in binaray string in python 3:

    count= 0
    maxcount = 0
    for i in str(bin(13)):
        if i == '1':
            count +=1
        elif count > maxcount:
            maxcount = count;
            count = 0
        else:
            count = 0
    if count > maxcount: maxcount = count        
    maxcount
    

提交回复
热议问题