Reputation: 47
The input is two integers in one line, x and y. I need to write a basically one-line program which does different things with x and y, and prints the result. Say, the output should be x + 1, y * y. Or list(range(x)), y // 2. Whatever operations but different. No def functions, also 'if' and 'for' are prohibited. As far as i understand, should look something like:
print(
*map(
lambda x: ??? ,
map(
int, input().split()
)
)
)
(But lambda can only do same thing to both inputs, right? ) I know it is possible and i've been thinking about this for three days to no avail. Most probable i miss something very obvious.
Upvotes: 1
Views: 85
Reputation: 85767
This seems to work just fine:
print(
*(lambda x: [int(x[0]) + 1, int(x[1]) * int(x[1])])(
input().split()
)
)
No fancy functional tricks or map
are needed.
Upvotes: 0
Reputation: 60974
Your lambda
function can take an x
and y
and turn them into pretty much any expression. Then you would call that function, doing the processing of the inputs outside of that lambda
print(*(lambda x, y: (x+1, y*y))(*map(int, input().split())))
print(*(lambda x, y: (list(range(x)), y//2))(*map(int, input().split())))
Upvotes: 1