Doing something like this
s = "12:00 PM"
hours, s = s.split(':')
hours = int(hours)
is there an elegant single-line idiom to do type conversion in the first element of a tuple before assignment?
Here is one option, but it's pretty messy
hours, s = (int(w) if w.isdigit() else w for w in s.split(':'))
source
share