質問編集履歴

8

修正

2019/10/04 05:39

投稿

yochun02
yochun02

スコア76

test CHANGED
File without changes
test CHANGED
@@ -48,19 +48,19 @@
48
48
 
49
49
  scala> val y: Seq[String] = List(s"${x(0)._1} - ${x(0)._2(0)}",
50
50
 
51
- | s"${x(0)._1} - ${x(0)._2(1)}",
51
+ s"${x(0)._1} - ${x(0)._2(1)}",
52
52
 
53
- | s"${x(0)._1} - ${x(0)._2(2)}",
53
+ s"${x(0)._1} - ${x(0)._2(2)}",
54
54
 
55
- | s"${x(1)._1} - ${x(1)._2(0)}",
55
+ s"${x(1)._1} - ${x(1)._2(0)}",
56
56
 
57
- | s"${x(1)._1} - ${x(1)._2(1)}",
57
+ s"${x(1)._1} - ${x(1)._2(1)}",
58
58
 
59
- | s"${x(1)._1} - ${x(1)._2(2)}",
59
+ s"${x(1)._1} - ${x(1)._2(2)}",
60
60
 
61
- | s"${x(2)._1} - ${x(2)._2(0)}",
61
+ s"${x(2)._1} - ${x(2)._2(0)}",
62
62
 
63
- | s"${x(2)._1} - ${x(2)._2(1)}")
63
+ s"${x(2)._1} - ${x(2)._2(1)}")
64
64
 
65
65
  ```
66
66
 
@@ -68,7 +68,7 @@
68
68
 
69
69
  ```plain
70
70
 
71
- y: Seq[String] = List(1 - hoge1, 1 - fuga1, 1 - piyo1, 2 - hoge1, 2 - fuga1, 2 - piyo1, 3 - hoge1, 3 - fuga1)
71
+ y: Seq[String] = List(1 - hoge1, 1 - fuga1, 1 - piyo1, 2 - hoge2, 2 - fuga2, 2 - piyo2, 3 - hoge3, 3 - fuga3)
72
72
 
73
73
  ```
74
74
 

7

修正

2019/10/04 05:39

投稿

yochun02
yochun02

スコア76

test CHANGED
File without changes
test CHANGED
@@ -52,15 +52,15 @@
52
52
 
53
53
  | s"${x(0)._1} - ${x(0)._2(2)}",
54
54
 
55
- | s"${x(1)._1} - ${x(0)._2(0)}",
55
+ | s"${x(1)._1} - ${x(1)._2(0)}",
56
56
 
57
- | s"${x(1)._1} - ${x(0)._2(1)}",
57
+ | s"${x(1)._1} - ${x(1)._2(1)}",
58
58
 
59
- | s"${x(1)._1} - ${x(0)._2(2)}",
59
+ | s"${x(1)._1} - ${x(1)._2(2)}",
60
60
 
61
- | s"${x(2)._1} - ${x(0)._2(0)}",
61
+ | s"${x(2)._1} - ${x(2)._2(0)}",
62
62
 
63
- | s"${x(2)._1} - ${x(0)._2(1)}")
63
+ | s"${x(2)._1} - ${x(2)._2(1)}")
64
64
 
65
65
  ```
66
66
 

6

補足説明

2019/10/04 05:36

投稿

yochun02
yochun02

スコア76

test CHANGED
File without changes
test CHANGED
@@ -15,10 +15,6 @@
15
15
  val y: Seq[Int] // > y = [1, 2, 3] となるようにしたい
16
16
 
17
17
  ```
18
-
19
-
20
-
21
- 追加の疑問
22
18
 
23
19
 
24
20
 
@@ -44,26 +40,36 @@
44
40
 
45
41
  // タプルの2番目の要素数の合計数を持つリストを生成したい(今の場合、3 + 3 + 2 = 8 個の要素数を持つ)
46
42
 
47
-
43
+ ```
48
44
 
49
45
  べた書きにすると
50
46
 
51
- val y: Seq[String] = List(s"${x(0)._1} - ${x(0)._2(0)}",
47
+ ```plain
52
48
 
53
- s"${x(0)._1} - ${x(0)._2(1)}",
49
+ scala> val y: Seq[String] = List(s"${x(0)._1} - ${x(0)._2(0)}",
54
50
 
55
- s"${x(0)._1} - ${x(0)._2(2)}",
51
+ | s"${x(0)._1} - ${x(0)._2(1)}",
56
52
 
57
- s"${x(1)._1} - ${x(0)._2(0)}",
53
+ | s"${x(0)._1} - ${x(0)._2(2)}",
58
54
 
59
- s"${x(1)._1} - ${x(0)._2(1)}",
55
+ | s"${x(1)._1} - ${x(0)._2(0)}",
60
56
 
61
- s"${x(1)._1} - ${x(0)._2(2)}",
57
+ | s"${x(1)._1} - ${x(0)._2(1)}",
62
58
 
63
- s"${x(2)._1} - ${x(0)._2(0)}",
59
+ | s"${x(1)._1} - ${x(0)._2(2)}",
64
60
 
61
+ | s"${x(2)._1} - ${x(0)._2(0)}",
62
+
65
- s"${x(2)._1} - ${x(0)._2(1)}")
63
+ | s"${x(2)._1} - ${x(0)._2(1)}")
64
+
65
+ ```
66
+
67
+ 実行結果
68
+
69
+ ```plain
70
+
71
+ y: Seq[String] = List(1 - hoge1, 1 - fuga1, 1 - piyo1, 2 - hoge1, 2 - fuga1, 2 - piyo1, 3 - hoge1, 3 - fuga1)
72
+
73
+ ```
66
74
 
67
75
  なのですが、mapやリスト操作に慣れていないので効率よい書き方がわかりません
68
-
69
- ```

5

補足

2019/10/04 02:49

投稿

yochun02
yochun02

スコア76

test CHANGED
File without changes
test CHANGED
@@ -44,4 +44,26 @@
44
44
 
45
45
  // タプルの2番目の要素数の合計数を持つリストを生成したい(今の場合、3 + 3 + 2 = 8 個の要素数を持つ)
46
46
 
47
+
48
+
49
+ べた書きにすると
50
+
51
+ val y: Seq[String] = List(s"${x(0)._1} - ${x(0)._2(0)}",
52
+
53
+ s"${x(0)._1} - ${x(0)._2(1)}",
54
+
55
+ s"${x(0)._1} - ${x(0)._2(2)}",
56
+
57
+ s"${x(1)._1} - ${x(0)._2(0)}",
58
+
59
+ s"${x(1)._1} - ${x(0)._2(1)}",
60
+
61
+ s"${x(1)._1} - ${x(0)._2(2)}",
62
+
63
+ s"${x(2)._1} - ${x(0)._2(0)}",
64
+
65
+ s"${x(2)._1} - ${x(0)._2(1)}")
66
+
67
+ なのですが、mapやリスト操作に慣れていないので効率よい書き方がわかりません
68
+
47
69
  ```

4

2019/10/04 02:46

投稿

yochun02
yochun02

スコア76

test CHANGED
File without changes
test CHANGED
@@ -42,4 +42,6 @@
42
42
 
43
43
  ]
44
44
 
45
+ // タプルの2番目の要素数の合計数を持つリストを生成したい(今の場合、3 + 3 + 2 = 8 個の要素数を持つ)
46
+
45
47
  ```

3

2019/10/04 01:18

投稿

yochun02
yochun02

スコア76

test CHANGED
File without changes
test CHANGED
@@ -24,10 +24,22 @@
24
24
 
25
25
  ```plain
26
26
 
27
- val y: Seq[String] // > y = ["1 = hoge1, fuga1, piyo1",
27
+ val y: Seq[String] // > y = ["1 - hoge1",
28
28
 
29
- "2 = hoge2, fuga2, piyo2",
29
+ "1 - fuga1",
30
30
 
31
+ "1 - piyo1",
32
+
33
+ "2 - hoge2",
34
+
35
+ "2 - fuga2",
36
+
37
+ "2 - piyo2",
38
+
31
- "3 = hoge3, fuga3"]
39
+ "3 - hoge3",
40
+
41
+ "3 - fuga3"
42
+
43
+ ]
32
44
 
33
45
  ```

2

訂正

2019/10/04 01:11

投稿

yochun02
yochun02

スコア76

test CHANGED
File without changes
test CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
 
20
20
 
21
- 追加
21
+ 追加の疑
22
22
 
23
23
 
24
24
 

1

追加質問

2019/10/03 13:42

投稿

yochun02
yochun02

スコア76

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  scalaで以下の処理をするにはどうしたらよいかわかりません。
2
2
 
3
- ```scala
3
+ ```plain
4
4
 
5
5
  val x: Seq[(Int, Seq[String])] = [
6
6
 
@@ -15,3 +15,19 @@
15
15
  val y: Seq[Int] // > y = [1, 2, 3] となるようにしたい
16
16
 
17
17
  ```
18
+
19
+
20
+
21
+ 追加質問
22
+
23
+
24
+
25
+ ```plain
26
+
27
+ val y: Seq[String] // > y = ["1 = hoge1, fuga1, piyo1",
28
+
29
+ "2 = hoge2, fuga2, piyo2",
30
+
31
+ "3 = hoge3, fuga3"]
32
+
33
+ ```