0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paizaラーニング「配列の連結 Python3編」

Posted at

私の解答

n, m = map(int, input().split())
li_n = [int(x) for x in input().split()]
li_m = [int(x) for x in input().split()]

for ele in li_n:
    print(ele)
for ele in li_m:
    print(ele)

リストを連結させる+演算子を知らなかったので、私の解答は上記のようになりました。

解答例1

values = input().split()
N = int(values[0])
M = int(values[1])

A = [0] * N
values = input().split()
for i in range(N):
    A[i] = int(values[i])

B = [0] * M
values = input().split()
for i in range(M):
    B[i] = int(values[i])

ans = A + B
for ele in ans:
    print(ele)
  • リストを連結させるとき、+ 演算子を使います。
  • x, y をリストとして、z = x + y のように書くと、リスト x の末尾にリスト y を連結したリスト z を生成することができます。

解答例2

N, M = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

ans = A + B
for ele in ans:
    print(ele)
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?