teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

8

修正

2019/10/04 05:39

投稿

yochun02
yochun02

スコア76

title CHANGED
File without changes
body CHANGED
@@ -23,16 +23,16 @@
23
23
  べた書きにすると
24
24
  ```plain
25
25
  scala> val y: Seq[String] = List(s"${x(0)._1} - ${x(0)._2(0)}",
26
- | s"${x(0)._1} - ${x(0)._2(1)}",
26
+ s"${x(0)._1} - ${x(0)._2(1)}",
27
- | s"${x(0)._1} - ${x(0)._2(2)}",
27
+ s"${x(0)._1} - ${x(0)._2(2)}",
28
- | s"${x(1)._1} - ${x(1)._2(0)}",
28
+ s"${x(1)._1} - ${x(1)._2(0)}",
29
- | s"${x(1)._1} - ${x(1)._2(1)}",
29
+ s"${x(1)._1} - ${x(1)._2(1)}",
30
- | s"${x(1)._1} - ${x(1)._2(2)}",
30
+ s"${x(1)._1} - ${x(1)._2(2)}",
31
- | s"${x(2)._1} - ${x(2)._2(0)}",
31
+ s"${x(2)._1} - ${x(2)._2(0)}",
32
- | s"${x(2)._1} - ${x(2)._2(1)}")
32
+ s"${x(2)._1} - ${x(2)._2(1)}")
33
33
  ```
34
34
  実行結果
35
35
  ```plain
36
- y: Seq[String] = List(1 - hoge1, 1 - fuga1, 1 - piyo1, 2 - hoge1, 2 - fuga1, 2 - piyo1, 3 - hoge1, 3 - fuga1)
36
+ y: Seq[String] = List(1 - hoge1, 1 - fuga1, 1 - piyo1, 2 - hoge2, 2 - fuga2, 2 - piyo2, 3 - hoge3, 3 - fuga3)
37
37
  ```
38
38
  なのですが、mapやリスト操作に慣れていないので効率よい書き方がわかりません

7

修正

2019/10/04 05:39

投稿

yochun02
yochun02

スコア76

title CHANGED
File without changes
body CHANGED
@@ -25,11 +25,11 @@
25
25
  scala> val y: Seq[String] = List(s"${x(0)._1} - ${x(0)._2(0)}",
26
26
  | s"${x(0)._1} - ${x(0)._2(1)}",
27
27
  | s"${x(0)._1} - ${x(0)._2(2)}",
28
- | s"${x(1)._1} - ${x(0)._2(0)}",
28
+ | s"${x(1)._1} - ${x(1)._2(0)}",
29
- | s"${x(1)._1} - ${x(0)._2(1)}",
29
+ | s"${x(1)._1} - ${x(1)._2(1)}",
30
- | s"${x(1)._1} - ${x(0)._2(2)}",
30
+ | s"${x(1)._1} - ${x(1)._2(2)}",
31
- | s"${x(2)._1} - ${x(0)._2(0)}",
31
+ | s"${x(2)._1} - ${x(2)._2(0)}",
32
- | s"${x(2)._1} - ${x(0)._2(1)}")
32
+ | s"${x(2)._1} - ${x(2)._2(1)}")
33
33
  ```
34
34
  実行結果
35
35
  ```plain

6

補足説明

2019/10/04 05:36

投稿

yochun02
yochun02

スコア76

title CHANGED
File without changes
body CHANGED
@@ -8,8 +8,6 @@
8
8
  val y: Seq[Int] // > y = [1, 2, 3] となるようにしたい
9
9
  ```
10
10
 
11
- 追加の疑問
12
-
13
11
  ```plain
14
12
  val y: Seq[String] // > y = ["1 - hoge1",
15
13
  "1 - fuga1",
@@ -21,15 +19,20 @@
21
19
  "3 - fuga3"
22
20
  ]
23
21
  // タプルの2番目の要素数の合計数を持つリストを生成したい(今の場合、3 + 3 + 2 = 8 個の要素数を持つ)
24
-
22
+ ```
25
23
  べた書きにすると
24
+ ```plain
26
- val y: Seq[String] = List(s"${x(0)._1} - ${x(0)._2(0)}",
25
+ scala> val y: Seq[String] = List(s"${x(0)._1} - ${x(0)._2(0)}",
27
- s"${x(0)._1} - ${x(0)._2(1)}",
26
+ | s"${x(0)._1} - ${x(0)._2(1)}",
28
- s"${x(0)._1} - ${x(0)._2(2)}",
27
+ | s"${x(0)._1} - ${x(0)._2(2)}",
29
- s"${x(1)._1} - ${x(0)._2(0)}",
28
+ | s"${x(1)._1} - ${x(0)._2(0)}",
30
- s"${x(1)._1} - ${x(0)._2(1)}",
29
+ | s"${x(1)._1} - ${x(0)._2(1)}",
31
- s"${x(1)._1} - ${x(0)._2(2)}",
30
+ | s"${x(1)._1} - ${x(0)._2(2)}",
32
- s"${x(2)._1} - ${x(0)._2(0)}",
31
+ | s"${x(2)._1} - ${x(0)._2(0)}",
33
- s"${x(2)._1} - ${x(0)._2(1)}")
32
+ | s"${x(2)._1} - ${x(0)._2(1)}")
33
+ ```
34
+ 実行結果
35
+ ```plain
36
+ y: Seq[String] = List(1 - hoge1, 1 - fuga1, 1 - piyo1, 2 - hoge1, 2 - fuga1, 2 - piyo1, 3 - hoge1, 3 - fuga1)
37
+ ```
34
- なのですが、mapやリスト操作に慣れていないので効率よい書き方がわかりません
38
+ なのですが、mapやリスト操作に慣れていないので効率よい書き方がわかりません
35
- ```

5

補足

2019/10/04 02:49

投稿

yochun02
yochun02

スコア76

title CHANGED
File without changes
body CHANGED
@@ -21,4 +21,15 @@
21
21
  "3 - fuga3"
22
22
  ]
23
23
  // タプルの2番目の要素数の合計数を持つリストを生成したい(今の場合、3 + 3 + 2 = 8 個の要素数を持つ)
24
+
25
+ べた書きにすると
26
+ val y: Seq[String] = List(s"${x(0)._1} - ${x(0)._2(0)}",
27
+ s"${x(0)._1} - ${x(0)._2(1)}",
28
+ s"${x(0)._1} - ${x(0)._2(2)}",
29
+ s"${x(1)._1} - ${x(0)._2(0)}",
30
+ s"${x(1)._1} - ${x(0)._2(1)}",
31
+ s"${x(1)._1} - ${x(0)._2(2)}",
32
+ s"${x(2)._1} - ${x(0)._2(0)}",
33
+ s"${x(2)._1} - ${x(0)._2(1)}")
34
+ なのですが、mapやリスト操作に慣れていないので効率よい書き方がわかりません
24
35
  ```

4

2019/10/04 02:46

投稿

yochun02
yochun02

スコア76

title CHANGED
File without changes
body CHANGED
@@ -20,4 +20,5 @@
20
20
  "3 - hoge3",
21
21
  "3 - fuga3"
22
22
  ]
23
+ // タプルの2番目の要素数の合計数を持つリストを生成したい(今の場合、3 + 3 + 2 = 8 個の要素数を持つ)
23
24
  ```

3

2019/10/04 01:18

投稿

yochun02
yochun02

スコア76

title CHANGED
File without changes
body CHANGED
@@ -11,7 +11,13 @@
11
11
  追加の疑問
12
12
 
13
13
  ```plain
14
- val y: Seq[String] // > y = ["1 = hoge1, fuga1, piyo1",
14
+ val y: Seq[String] // > y = ["1 - hoge1",
15
+ "1 - fuga1",
16
+ "1 - piyo1",
15
- "2 = hoge2, fuga2, piyo2",
17
+ "2 - hoge2",
18
+ "2 - fuga2",
19
+ "2 - piyo2",
16
- "3 = hoge3, fuga3"]
20
+ "3 - hoge3",
21
+ "3 - fuga3"
22
+ ]
17
23
  ```

2

訂正

2019/10/04 01:11

投稿

yochun02
yochun02

スコア76

title CHANGED
File without changes
body CHANGED
@@ -8,7 +8,7 @@
8
8
  val y: Seq[Int] // > y = [1, 2, 3] となるようにしたい
9
9
  ```
10
10
 
11
- 追加
11
+ 追加の疑
12
12
 
13
13
  ```plain
14
14
  val y: Seq[String] // > y = ["1 = hoge1, fuga1, piyo1",

1

追加質問

2019/10/03 13:42

投稿

yochun02
yochun02

スコア76

title CHANGED
File without changes
body CHANGED
@@ -1,9 +1,17 @@
1
1
  scalaで以下の処理をするにはどうしたらよいかわかりません。
2
- ```scala
2
+ ```plain
3
3
  val x: Seq[(Int, Seq[String])] = [
4
4
  (1, ["hoge1", "fuga1", "piyo1"]),
5
5
  (2, ["hoge2", "fuga2", "piyo2"]),
6
6
  (3, ["hoge3", "fuga3"])
7
7
  ]
8
8
  val y: Seq[Int] // > y = [1, 2, 3] となるようにしたい
9
+ ```
10
+
11
+ 追加質問
12
+
13
+ ```plain
14
+ val y: Seq[String] // > y = ["1 = hoge1, fuga1, piyo1",
15
+ "2 = hoge2, fuga2, piyo2",
16
+ "3 = hoge3, fuga3"]
9
17
  ```