Suppose the input is: string integer integer. Now i need to map only the 2nd and 3rd input to integer.
name, d, j = input().split()
d = int(d)
j = int(j)
Is this the only way to do it?
Suppose the input is: string integer integer. Now i need to map only the 2nd and 3rd input to integer.
name, d, j = input().split()
d = int(d)
j = int(j)
Is this the only way to do it?
You could also do this:
name, d, j = input().split()
d,j = map(int,[d,j])
But I don't really see the benefit. There's nothing wrong with what you already have. Remember, fewer lines of code is not a goal unto itself.
name, d, j = [int(b) if i >=1 else b for i,b in enumerate(input().split())]
For the purely academic challenge of squeezing it into one line, you could use the singleton list/iterator trick:
name, d, j = next((x, *map(int, y)) for x, *y in ['john 3 4'.split()])
But pls never do this in production code ;)