用python 找到不存在的数字
先用bash脚本排序,然后用python脚本找出丢失的数字。当然,也可以完全在python脚本中完成。#!/usr/bin/python
#filename:findlost.py
#author:zhouhh
#http://blog.csdn.net/ablo_zhou
#email:ablozhou@gmail.com
#date:2008.3.31
#Findoutwhatnumberislostfromafile
importos
infilename=raw_input("infilename:");
outfilename=raw_input("outfilename:");
ifinfilename=="":
infilename="rawpack";
ifoutfilename=="":
outfilename="outfile";
cmd=("sort.sh",infilename,outfilename)
os.system(''.join(cmd))
f=open(outfilename);
i=0
pkid=0
count=0
whileTrue:
line=f.readline()
iflen(line)==0:
f.close()
break
pkid=int(line)
ifpkid>i:
print"lostpackage",i
i+=1
count+=1
i+=1
print"================================="
print"totalpackagenumis",pkid,",lostpackagecount:",count
执行结果:
$./findlost.py
infilename:
outfilename:
./sort.sh,rawpack,outfile
lostpackage1707
lostpackage2126
lostpackage2139
lostpackage2278
lostpackage2280
lostpackage2475
lostpackage2763
lostpackage3014
lostpackage3072
lostpackage3165
lostpackage3271
=================================
totalpackagenumis3778,lostpackagecount:11
页:
[1]