質問編集履歴
1
ソースコードにコメントを追加
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
class Read_file:
|
|
28
|
+
class Read_file: #ファイルの読み込み
|
|
29
29
|
def __init__(self):
|
|
30
30
|
self.file = []
|
|
31
31
|
|
|
@@ -35,33 +35,34 @@
|
|
|
35
35
|
self.file = name.split("\n")
|
|
36
36
|
return self.file
|
|
37
37
|
|
|
38
|
-
class Undup_list:
|
|
38
|
+
class Undup_list:
|
|
39
39
|
def __init__(self, list):
|
|
40
40
|
self.list = list
|
|
41
41
|
|
|
42
|
-
def undup_list(self):
|
|
42
|
+
def undup_list(self): #名前の取り出し
|
|
43
43
|
new_list = []
|
|
44
44
|
for x in self.list: # creating unduplicated name list
|
|
45
45
|
if x not in new_list:
|
|
46
46
|
new_list.append(x)
|
|
47
47
|
return sorted(new_list)
|
|
48
48
|
|
|
49
|
-
def count_element(self, element):
|
|
49
|
+
def count_element(self, element): #elementの数をカウント
|
|
50
|
+
|
|
50
51
|
return self.list.count(element)
|
|
51
52
|
|
|
52
53
|
if __name__=='__main__'
|
|
53
54
|
name_in = []
|
|
54
55
|
name_list =[]
|
|
55
56
|
name_count =[]
|
|
56
|
-
file_in = Read_file()
|
|
57
|
+
file_in = Read_file() #インスタンス生成
|
|
57
58
|
name_in = file_in.read_file()
|
|
58
59
|
|
|
59
|
-
name = Undup_list(name_in)
|
|
60
|
+
name = Undup_list(name_in) #インスタンス生成
|
|
60
61
|
name_list = name.undup_list()
|
|
61
62
|
|
|
62
63
|
for i in range(len(name_list)): #counting names
|
|
63
64
|
name_count.append(name.count_element(name_list[i]))
|
|
64
|
-
print(dict(zip(name_list, name_count))) #
|
|
65
|
+
print(dict(zip(name_list, name_count))) #辞書に変換
|
|
65
66
|
```
|
|
66
67
|
|
|
67
68
|
## 質問内容
|