Python关于六级单词挑选的第一次尝试

各位看官,你们好
本人第一次写博客,有不足的地方还请多指教
谢谢

挑选词频txt文件与六级4500词中的不同词

#文件路径
path1 = “C:\Users\22\Desktop\六级4次以上词频.txt”
path2 =“C:\Users\22\Desktop\6级单词.txt”
path_en1 = “C:\Users\22\Desktop\6级单词end1.txt”
path_end2 = “C:\Users\22\Desktop\6级单词end2.txt”

def getDagang():
raw_dagang1 = []
dagang = open(path1,encoding=None,errors=‘ignore’) .read()
dagang = dagang.lower()
for ci in dagang:
c = raw_dagang1.append(ci)
dagang.close()

def getRaw():
raw_danci = []
raw_file = open(path2,encoding=None,errors=‘ignore’) .read()
raw_file = raw_file.lower()
for ci1 in raw_file:
cc = raw_danci.append(ci1)
raw_file.close()

def saiXuan():
chuli_end1 = []
chuli_end2 = []
out_file1 = open(path_end1,‘w’)
out_file2 = open(path_end2,‘w’)
if ci == ci1:
m1 = chuli_end1.append(chuli_end1)
m1 = out_file1.writelines()
else:
m2 = chuli_end2.append(chuli_end2)
m2 = out_file2.writelines()
out_file1.close()
out_file2.close()

a = getDagang()
b = getRaw()
c = saiXuan()

print(a)
print(b)
print©

#文件路径
path1 = “六级4次以上词频.txt”
path2 =“6级单词.txt”
path_end1 = “6级单词end1.txt”
path_end2 = “6级单词end2.txt”

raw_dagang1 = []
dagang = open(path1,encoding=‘utf-8’)
da = dagang.readlines()
for ci in da:
c = raw_dagang1.append(ci.strip().lower())
dagang.close()

raw_danci = []
raw_file = open(path2,encoding=‘utf-8’)
raw = raw_file.readlines()
for ci1 in raw:
cc = raw_danci.append(ci1.strip().lower())
raw_file.close()

#判断单词是否相同,相同和不同的各放在一个列表,弄成文件

chuli_end1 = []
chuli_end2 = []
out_file1 = open(path_end1,‘w’,encoding=‘utf-8’)
out_file2 = open(path_end2,‘w’,encoding=‘utf-8’)

for i in raw_dagang1:
if i in raw_danci:
chuli_end1.append(i)

out_file1.write(’\n’.join(chuli_end1))

for i in chuli_end1:
if i in raw_danci:
raw_danci.remove(i)
if i in raw_dagang1:
raw_dagang1.remove(i)

out_file2.write(’\n’.join(raw_danci+raw_dagang1))
out_file1.close()
out_file2.close()

猜你喜欢

转载自blog.csdn.net/new_boysmm/article/details/112370881