回答編集履歴

4

修正

2020/06/22 02:47

投稿

ForestSeo
ForestSeo

スコア2722

test CHANGED
@@ -26,4 +26,24 @@
26
26
 
27
27
  # Matsuda: 1人
28
28
 
29
- ```[Counter](https://note.nkmk.me/python-collections-counter/)を使うと簡単
29
+ ```[Counter](https://note.nkmk.me/python-collections-counter/)を使う
30
+
31
+ ***
32
+
33
+ 5行目が複雑ですが、
34
+
35
+ ```Python
36
+
37
+ companies = [l[2] for l in lst if 30 <= int(l[1]) <= 39]
38
+
39
+ # ↓
40
+
41
+ companies = []
42
+
43
+ for l in lst:
44
+
45
+ if 30 <= int(l[1]) <= 39:
46
+
47
+ companies.append(l[2])
48
+
49
+ ```と同じこと

3

修正

2020/06/22 02:47

投稿

ForestSeo
ForestSeo

スコア2722

test CHANGED
@@ -26,4 +26,4 @@
26
26
 
27
27
  # Matsuda: 1人
28
28
 
29
- ```
29
+ ```[Counter](https://note.nkmk.me/python-collections-counter/)を使うと簡単

2

修正

2020/06/22 02:44

投稿

ForestSeo
ForestSeo

スコア2722

test CHANGED
@@ -4,33 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- lst = [
7
+ lst = # あなたのリスト
8
-
9
- "X.L. 32 MITSUOKA HIMIKO 33-64",
10
-
11
- "Z.Y. 56 TOYOTA C-HR 55-11",
12
-
13
- "M.F. 48 HONDA VEZEL 63-79",
14
-
15
- "P.Y. 28 DAIHATSU BOON 58-85",
16
-
17
- "H.C. 41 NISSAN X-TRAIL 33-52",
18
-
19
- "W.L. 32 TOYOTA C-HR 44-84",
20
-
21
- "Z.T. 44 NISSAN GT-R 34-49",
22
-
23
- "Z.E. 53 NISSAN GT-R 94-31",
24
-
25
- "E.P. 36 SUZUKI JIMNY 52-81",
26
-
27
- "O.X. 33 Matsuda CX-8 79-24",
28
-
29
- "E.T. 47 SUZUKI SOLIO 46-21",
30
-
31
- "D.N. 27 SUZUKI SOLIO 45-22",
32
-
33
- ]
34
8
 
35
9
  lst = [s.split() for s in lst] # splitして2次元配列に
36
10
 

1

修正

2020/06/22 02:42

投稿

ForestSeo
ForestSeo

スコア2722

test CHANGED
@@ -5,14 +5,6 @@
5
5
 
6
6
 
7
7
  lst = [
8
-
9
- "T.T. 26 HONDA CR-V 76-74",
10
-
11
- "J.L. 25 MITSUBISHI OUTLANDER 31-92",
12
-
13
- "O.E. 57 MITSUBISHI DELICA 28-88",
14
-
15
- "P.C. 22 HONDA CR-V 13-89",
16
8
 
17
9
  "X.L. 32 MITSUOKA HIMIKO 33-64",
18
10
 
@@ -40,24 +32,24 @@
40
32
 
41
33
  ]
42
34
 
43
- lst = [s.split() for s in lst]
35
+ lst = [s.split() for s in lst] # splitして2次元配列に
44
36
 
45
- companies = [l[2] for l in lst if 30 <= int(l[1]) <= 39]
37
+ companies = [l[2] for l in lst if 30 <= int(l[1]) <= 39] # 30~39歳の人の会社のリスト
46
38
 
47
- counts = Counter(companies)
39
+ counts = Counter(companies) # どの会社の車を何人の人が持っているか
48
40
 
49
41
  for k,v in counts.items():
50
42
 
51
- print(f"{k}: {v}人")
43
+ print(f"{k}: {v}人") # 結果
52
44
 
53
45
 
54
46
 
55
- # MITSUOKA:1人
47
+ # MITSUOKA: 1人
56
48
 
57
- # TOYOTA:1人
49
+ # TOYOTA: 1人
58
50
 
59
- # SUZUKI:1人
51
+ # SUZUKI: 1人
60
52
 
61
- # Matsuda:1人
53
+ # Matsuda: 1人
62
54
 
63
55
  ```