x='2013:02:01'
y,m,d=x.split(':')
Produces y,m,d as strings. But how do I produce them as ints using only 1 line
Failed:
y,m,d=int(y.split(':'))
y,m,d=int(y),int(m),int(d)=y.split(':')
y, m, d = map(int, x.split(':'))
map
applies the function to each of the elements in the iterable. In this case it will apply int
to each of the values returned by split
and give you the result.
Using list comprehension will do the trick:
>>> x='2013:02:01'
>>> y,m,d=[int(n) for n in x.split(':')]
>>> y
2013
>>> d
1
>>> m
2