I have this snippet:
s = "A 1 B 2"
a, a1, b, b1 = s.split()
a1 = int(a1)
b1 = int(b1)
I was wondering if there is anyway of unpacking and converting to int
or anything else at the same time. I can also write the snippet as follows:
s = "A 1 B 2"
a, a1, b, b1 = (int(x) if i in (1, 3) else i, x for x in enumerate(s.split()))
But I wanted to know if there is a shorter version. Something like
a, int(a1), b, int(b1) = s.split()
which would make something like this also possible:
s = "A 1 B 2.3"
a, int(a1), b, float(b1) = s.split()