回答編集履歴

1

修正

2020/10/01 05:07

投稿

nto
nto

スコア1438

test CHANGED
@@ -53,3 +53,55 @@
53
53
  print(string, value, result)
54
54
 
55
55
  ```
56
+
57
+
58
+
59
+ ### 質問内容の修正に伴い、コード修正
60
+
61
+ ```python
62
+
63
+ lst = []
64
+
65
+ with open('list_file.txt', 'r') as c:
66
+
67
+ for line in c:
68
+
69
+ string, digit = line.split()
70
+
71
+ lst.append([string, int(digit)])
72
+
73
+
74
+
75
+ data = {}
76
+
77
+ with open('data_file.txt', 'r') as f:
78
+
79
+ for line in f:
80
+
81
+ string, digit = line.split()
82
+
83
+ data[string] = int(digit)
84
+
85
+
86
+
87
+ for l in lst:
88
+
89
+ string = l[0] # 可読性をよくする為だけにわざと代入しています
90
+
91
+ digit = l[1] # 可読性をよくする為だけにわざと代入しています
92
+
93
+ if string in [key for key in data.keys()]:
94
+
95
+ value = data[string]
96
+
97
+ result = digit - data[string]
98
+
99
+ else:
100
+
101
+ value = 0
102
+
103
+ result = digit
104
+
105
+ print(string, value, result, sep='\t')
106
+
107
+ ```