Python question

Asked 2 years ago, Updated 2 years ago, 14 views

a = int(input())
c = []
b = []
q = []
for i in range(a):
    c.append(input().split())
for u in range(len(c)):
    for z in c[u]:
        q.append(int(z))
        b.append(q)
        while len(q) == 0:
            del q[0:-1]
            del q[-1]
print(b)

It's an index

4
234 234 234 234
123 123 123
12 12
1

I'll put in the input value When printing [[234,234,234,234,234], [123,123,123], [1] I want this to come out ㅠ<

python

2022-09-22 19:47

2 Answers

It's a very simple way to put it like this way.

try_cnt = int(input())
result = [list(map(int, input().split())) for _ in range(try_cnt)]
print(result)

3
123 123 123
12 12
1
[[123, 123, 123], [12, 12], [1]]


2022-09-22 19:47

line_num = int(input())
arr_concat = []

for i in range(line_num):
    # # read line and split
    arr = input().split()

    # # if you need type casting,
    arr_concat.append(list(map(lambda x: int(x), arr)))
    # # or
    # # arr_concat.append(arr)

print(arr_concat)


2022-09-22 19:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.