python dictionary的使用
来源:互联网 发布:java垃圾回收机制原理 编辑:程序博客网 时间:2024/06/06 08:43
#遍历目录,打印文件重复数目,并排序
import sys
import string
from operator import itemgetter
def stat(pathname):
dict = {"null":0}
dict.clear()
for root, dirs, files in os.walk(pathname):
for file in files:
filename = os.path.join(root, file)
if dict.has_key(file):
dict[file] = dict[file] + 1
else:
dict[file] = 1
for key,value in zip(dict.keys(), dict.values()):
print("%s %d" %(key,value))
#sort dict and the output is list
sortlist = sorted(dict.iteritems(),key=itemgetter(1), reverse=True)
file = open("stat.txt", "w")
for item in sortlist:
file.writelines("%s %d\n" %(item[0], item[1]))
file.close();
if __name__=="__main__":
stat(sys.argv[1])
0 0
- python dictionary的使用
- Python dictionary items()系列函数的使用
- Python dictionary items()系列函数的使用
- python Dictionary字典使用
- dictionary的例子 python
- python中字典和字符串的使用 dictionary string
- dictionary的使用.net
- Dictionary对象的使用
- dictionary的使用
- dictionary的使用
- dictionary的使用
- iOS dictionary的使用
- Dictionary 的使用
- python Dictionary
- python Dictionary
- Python Dictionary
- Python Dictionary
- python dictionary
- TCP/IP源码--不错的博客
- 12月总结
- Find Peak Element
- ListView之SimpleAdapter的使用 .
- android传感器摇一摇功能
- python dictionary的使用
- 感谢你让我上场
- ListView之BaseAdapter的使用 .
- 分支-01. 超速判断
- 由于standby_file_management造成的dg的问题
- Facebook和Google如何激发工程师的创造力
- word流程图被固定后无法修改的问题
- Java基础----Character
- 设备驱动-模块参数-ubuntu12.04