回答編集履歴

1

追記

2020/12/10 05:35

投稿

jeanbiego
jeanbiego

スコア3966

test CHANGED
@@ -19,3 +19,57 @@
19
19
  # [[1, 10, 0.1], [2, 20, 0.2], [3, 30, 3.0]]
20
20
 
21
21
  ```
22
+
23
+
24
+
25
+ ## 追記
26
+
27
+ n番目まで(ただし計算は最後までされてしまいます)
28
+
29
+ ```python3
30
+
31
+ time = [1,2,3,30]
32
+
33
+ freq = [10,20,30,300]
34
+
35
+ Pxx = [0.1,0.2,3.0]
36
+
37
+ n = 1
38
+
39
+ data = [[t, f, p] for i, (t, f, p) in enumerate(zip(time,freq,Pxx)) if i <= n]
40
+
41
+ print(data)
42
+
43
+ # [[1, 10, 0.1], [2, 20, 0.2]]
44
+
45
+ ```
46
+
47
+
48
+
49
+ 元listの要素が多すぎる場合はこちら
50
+
51
+ ```python3
52
+
53
+ time = [1,2,3,30]
54
+
55
+ freq = [10,20,30,300]
56
+
57
+ Pxx = [0.1,0.2,3.0]
58
+
59
+ n = 1
60
+
61
+ data = list()
62
+
63
+ for i, (t, f, p) in enumerate(zip(time,freq,Pxx)):
64
+
65
+ if i > n:
66
+
67
+ break
68
+
69
+ data.append([t, f, p])
70
+
71
+ print(data)
72
+
73
+ # [[1, 10, 0.1], [2, 20, 0.2]]
74
+
75
+ ```