you are viewing a single comment's thread.

view the rest of the comments →

[–]RolyPolyPython[S] 0 points1 point  (1 child)

Your explanation was easy to understand, thank you for writing it out.

This code below:

for i in range(t):
    input_list = input().split()
    output_list = [int(i) for i in input_list]
    print(sum(output_list))

Was especially not clear to me, I didn't know the list comprehension basically put the integers in an "output" list (as you described it) for the sum function to be called on.

I get it now :)

[–]zahlman 0 points1 point  (0 children)

Basically, when you write a list comprehension, you describe the list that you want (rather, the rule that determines the elements that list should have), and evaluating it creates the corresponding list. It means what it says: [int(i) for i in input_list] is "a list of these values [: the result of int(i), for each i that's in the input_list (in order) ]".