1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
| #!/usr/bin/python
| # -*- coding: UTF-8 -*-
|
| import sys
| import numpy as np
|
| '''
| 比较两个文件中的成语(4字) 有多少是重复的。
|
| '''
|
| file1= sys.argv[1]
| file2 = sys.argv[2]
|
| array_1 = []
| array_2 = []
|
| with open(file1, 'r', encoding='utf-8-sig') as f:
| for word in f.read().splitlines():
| if len(word) ==4:
| array_1.append(word)
| else:
| print(word)
|
| with open(file2, 'r', encoding='utf-8-sig') as f:
| for word in f.read().splitlines():
| if len(word) ==4:
| array_2.append(word)
| else:
| print(word)
|
|
| print(len(array_1))
| print(len(array_2))
|
| array_same = []
|
| for item in array_2:
| for it in array_1:
| if item == it :
| array_same.append(item)
|
| print(len(array_same))
| print(array_same)
|
|