Skip to main content
 首页 » 编程设计

python之使用python查找系列中缺失的数字

2025年05月04日15cloudgamer

<分区>

我有一个包含数字的文件,我需要找到丢失的文件。

cat head.txt 
7045000000 
7045000001 
7045000003 

如您所见,号码 7045000002 丢失了。此代码无效:

check=int(7044999999) 
with open('head.txt' , 'r') as f: 
    for line in f: 
        myl = line[:5] 
        if myl == '70450': 
            if int(line) == check+1: 
                check = int(line) 
            else: 
                check = int(line)+1 
                print check 

数字应以 70450 开头,并且“myl”变量是必需的。