Created
February 1, 2018 14:07
-
-
Save zhangxigithub/ba79ff58a3c9d14aebc48abcda733965 to your computer and use it in GitHub Desktop.
RepeatCodeCount
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
result = {"":0} | |
for root, dirs, files in os.walk(".", topdown=False): | |
for name in files: | |
path = os.path.join(root, name) | |
ext = os.path.splitext(name)[1] | |
if ext == ".swift": | |
f = open(path, "r") | |
code = f.readline() | |
for line in f.readlines(): | |
key = line.replace(' ','').replace('{','').replace('}','').replace('\n','').replace('\t','').replace('//','') | |
key = key.replace('/*','') | |
key = key.replace('*/','') | |
if key != "": | |
if key in result: | |
result[key] += 1 | |
else: | |
result[key] = 0 | |
f.close() | |
sort = sorted(result.items(),key = lambda x:x[1],reverse = True) | |
print "==========================================================================================" | |
for i in range(30): | |
print "{:<80}{:10}".format(sort[i][0],sort[i][1]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment