Find gaps in a sequence of Strings

后端 未结 4 1881
执念已碎
执念已碎 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:13

    For storing sequence of 2 millions ints you can use bitarray. Here each bit means one integer (the integer of that index in bitarray). Example code:

    gaps = []
    # bitarray is 0 based
    a = bitarray.bitarray(total + 1)
    a.setall(False)
    for sid in curr_ids:
        a[int(sid)] = True
    for i in range(1, total):
        if not a[i]:
            gaps.append('%07d' %(i))
    return gaps
    

提交回复
热议问题