I am very new in Python, and I am really surprised at the following line of code.
print (sum(int(x) for x in raw_input().split()))
I cannot understand what is happening inside with my Java brain, especially the way x passed to int() from for loop.
raw_input().split()returns an array for each line of input.(int(x) for x in a)is a generator expression which appliesintto each line of input, converting it to an integer. The result of the generator expression is an array of integers; one for each line of input.Finally
sumtakes the sum of all the elements in the array, and of courseprintwill output the whole lot. So the result is code which produces the sum of all lines of input where each line is a number.