def Findhf(text): Headerfile=[] x=text.split("\n") #print(x) for i in x: if('#include' in i): Headerfile.append(i) #print(Headerfile) return Headerfile
def Findo(text): others=[]
x=text.split("\n") #print(x) for i in x: if('#include' not in i): if('main' not in i): others.append(i) else: break #print(others) return others
def Findm(text): real=[] rep=[] count=1 x=text.split("\n") for i in x: if(count==1): if('main' in i): #print(i) count=count-1 else: if('}' != i): real.append(i) else: print('found finish') for a in real: if('write' in a): te=a.split(',') del te[0] te.pop() place=','.join(te) place=' mywrite('+place+');' rep.append(place) else: rep.append(a) #print(rep) return rep
f = open("test.txt") lines = f.readlines() count = {} for line in lines: tokens = line.strip().split(' ') for token in tokens: if token not in count: count[token] = 0 count[token] += 1
for word in count: print word,count[word]
''' #!/usr/bin/python # -*- coding: UTF-8 -*- num=[]; i=2 for i in range(2,100): j=2 for j in range(2,i): if(i%j==0): break else: num.append(i) print(num) '''
''' 求和 total = 0 for i in range(1,101): total+=i print total
输出素数 def judge(x): for i in range(2,x): if x%i==0: return false return true for i in range(2,101): if judge(i): print i '''