Find gaps in a sequence of Strings

后端 未结 4 1893
执念已碎
执念已碎 2020-12-20 17:45

I have got a sequence of strings - 0000001, 0000002, 0000003.... upto 2 million. They are not contiguous. Meaning there are gaps. Say after 0000003 the next str

4条回答
  •  不知归路
    2020-12-20 18:10

    I would suggest take it int rather than string for processing and then making it a string again in output

    j=0
    n=2000000
    #create a list of int number from your string
    foo = [i for i in range(n)]
    #creating gaps
    foo.remove(1)
    foo.remove(50)
    while jj:
                print '%07d'%j
                j+=1
            j+=1
    

提交回复
热议问题