# -*- coding:utf-8 -*-
# 练习
# 从1加到100
totol = 0
for i in range(1, 101):
totol += i
# print totol
# 打出100以内的质数
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
# 判断文件中单词出现的次数
f = open("demo.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]
分类: Python
0 条评论