Search code examples
pythonpython-3.xinputtestcase

Python getting input for test cases in competitive coding


How do I take input for T test cases with N values in a list.

Where T is the number of test cases and N is the length of inputs to be taken into a list

3
3
2 2 2
3
1 2 3
4
2 3 4 5

I want to get out the lists to work on them like:

[2, 2, 2]
[1, 2, 3]
[2, 3, 4, 5]

Solution

  • You can simply use string's split method to separate elements by ' ' (space) and map function to convert string input values to integers.

    for _ in range(int(input())):
        input()    # gets length of list, but doesn't store it
        input_list = list(map(int, input().split()))
        print(input_list)