回答編集履歴
1
追記
test
CHANGED
@@ -1,3 +1,49 @@
|
|
1
|
+
【追記】
|
2
|
+
|
3
|
+
```Python
|
4
|
+
|
5
|
+
listcode=[['A', 'ABC', '1'], ['B', 'DEF', '2'], ['C', 'ABC', '3'], ['D', 'XYZ', '4'],['A', 'ABC', '1'], ['B', 'DEF', '2'], ['C', 'ABC', '3'], ['D', 'XYZ', '4']]
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
y=1
|
10
|
+
|
11
|
+
for i in range(0,len(listcode)):
|
12
|
+
|
13
|
+
if y==len(listcode):
|
14
|
+
|
15
|
+
pass
|
16
|
+
|
17
|
+
else:
|
18
|
+
|
19
|
+
for x in range(i+1,len(listcode)):
|
20
|
+
|
21
|
+
if listcode[i][1]==listcode[x][1]:
|
22
|
+
|
23
|
+
listcode[i][2]=int(listcode[i][2])+int(listcode[x][2])
|
24
|
+
|
25
|
+
del listcode[x]
|
26
|
+
|
27
|
+
if x == len(listcode) -1:
|
28
|
+
|
29
|
+
break
|
30
|
+
|
31
|
+
x=x-1
|
32
|
+
|
33
|
+
y=y+1
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
print(listcode)
|
38
|
+
|
39
|
+
#[['A', 'ABC', 8], ['B', 'DEF', 4], ['D', 'XYZ', 8]]
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
---
|
46
|
+
|
1
47
|
質問者さんのコードを改良しました。
|
2
48
|
|
3
49
|
|