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

質問編集履歴

3

説明を明確にした

2020/05/12 00:43

投稿

Spursfun2002
Spursfun2002

スコア15

title CHANGED
File without changes
body CHANGED
@@ -67,4 +67,5 @@
67
67
  ```
68
68
  1 2 4
69
69
  ```
70
+ となってしまいました。
70
- となってしまいました。反対にするにはどうすればいのでしょうか?
71
+ リストの順番をキープするにはどのよすればいのでしょうか?

2

説明を明確にした

2020/05/12 00:43

投稿

Spursfun2002
Spursfun2002

スコア15

title CHANGED
File without changes
body CHANGED
@@ -30,4 +30,41 @@
30
30
  Enter a list of numbers separated by spaces:
31
31
  4 3 5 2 5 1 3 5
32
32
  4 3 5 5
33
- ```
33
+ ```
34
+
35
+ 求めたいOutput
36
+ ```
37
+ 4 2 1
38
+ ```
39
+
40
+ 自分で改善してみた結果
41
+ ```
42
+ # Read a list of integers from input.
43
+ # Each number is separated by a space.
44
+ # Do not modify line 5.
45
+ print("Enter a list of numbers separated by spaces:")
46
+ list = [int(s) for s in input().split()]
47
+
48
+ # the variable 'list' contains the list of numbers
49
+ # this is to show you the list, you can delete this line.
50
+
51
+ # your code goes here.
52
+ list.sort()
53
+ num = len(list)
54
+
55
+ if list[0] != list[1]:
56
+ print(list[0], end = ' ')
57
+
58
+ for x in range(1, num-1):
59
+ if (list[x] != list[x + 1] and list[x] != list[x - 1]):
60
+ print(list[x], end = ' ')
61
+
62
+ if list[num - 2] != list[num - 1]:
63
+ print(list[num - 1], end = ' ')
64
+ ```
65
+
66
+ こうなったのですが肝心のOutputが
67
+ ```
68
+ 1 2 4
69
+ ```
70
+ となってしまいました。反対にするにはどうすればよいのでしょうか?

1

説明を明確にした

2020/05/12 00:39

投稿

Spursfun2002
Spursfun2002

スコア15

title CHANGED
@@ -1,1 +1,1 @@
1
- リストの中から重複数字を排除し、リストを作す方法について
1
+ リストの中から1回か使われない数字をす方法について
body CHANGED
@@ -1,3 +1,5 @@
1
+ すいません、言い方が悪かったです。1回しか使われない数字をOutputとして出す場合どうすればいいのかと。。。
2
+
1
3
  ```
2
4
  # Read a list of integers from input.
3
5
  # Each number is separated by a space.