Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
5-liner: longest conditional line I've ever written solution in Clear category for Time Converter (12h to 24h) by Stensen
from re import split
def time_converter(time):
h, m, period = split(r'[ :]', time)
h = int(h) - 12 if period == 'a.m.' and int(h) == 12 else int(h) + 12 if period == 'p.m.' and 1 <=int(h)<= 11 else h
return f'{str(h).zfill(2)}:{m}'
Oct. 24, 2020
Comments: