`
totoxian
  • 浏览: 1031080 次
  • 性别: Icon_minigender_2
  • 来自: 西安
文章分类
社区版块
存档分类
最新评论

用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[rawpack]:");
outfilename
=raw_input("outfilename[outfile]:");

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[rawpack]:
outfilename[outfile]:
./sort.sh,rawpack,outfile
lostpackage
1707
lostpackage
2126
lostpackage
2139
lostpackage
2278
lostpackage
2280
lostpackage
2475
lostpackage
2763
lostpackage
3014
lostpackage
3072
lostpackage
3165
lostpackage
3271
=================================
totalpackagenumis
3778,lostpackagecount:11
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics