Implement a class/function, which should parse time expressed as `HH:MM:SS`, or `null/nil/None` otherwise.

Any extra characters, or minutes/seconds higher than 59 make the input invalid, and so should return `null/nil/None`.

Difficulty: EASY
Starter code: def to_seconds(time):
	

Solutions:
def to_seconds(time):
	try:
		(s, m, h) = (int(time[-2:]), int(time[3:5]), int(time[:2]))
		return s + m * 60 + h * 3600 if m < 60 and s < 60 and (len(time) == 8) else None
	except:
		return None


import re

def to_seconds(time):
	if bool(re.match('[0-9][0-9]:[0-5][0-9]:[0-5][0-9]\\Z', time)):
		return int(time[:2]) * 3600 + int(time[3:5]) * 60 + int(time[6:8])
	else:
		return None


from re import compile, match
REGEX = compile('^(?P<h>\\d{2}):(?P<m>[0-5]\\d):(?P
[0-5]\\d)$')

def to_seconds(time):
	m = match(REGEX, time)
	if m and time[slice(*m.span())] == time:
		hms = m.groupdict()
		return int(hms['h']) * 3600 + int(hms['m']) * 60 + int(hms['s'])


import re
from functools import reduce
HH_MM_SS_PATTERN = re.compile('\\A(\\d\\d):([0-5]\\d):([0-5]\\d)\\Z')

def to_seconds(time):
	m = HH_MM_SS_PATTERN.search(time)
	if m:
		return reduce(lambda x, y: x * 60 + int(y), m.groups(), 0)
	return None


import re

def to_seconds(time):
	match = re.fullmatch('(\\d{2}):([0-5][0-9]):([0-5][0-9])', time)
	return int(match.group(1)) * 3600 + int(match.group(2)) * 60 + int(match.group(3)) if match else None


import re

def to_seconds(time):
	match = re.match('(\\d\\d):([0-5]\\d):([0-5]\\d)\\Z', time)
	return match and sum((int(n) * 60 ** i for (i, n) in enumerate(match.groups()[::-1])))


import re
to_seconds = lambda t: sum((int(j) * i for (i, j) in zip([3600, 60, 1], t.split(':')))) if re.sub('^\\d{2}:[0-5][0-9]:[0-5][0-9]$', '', t) == '' else None


def to_seconds(time):
	try:
		(h, m, s) = map(int, time.split(':'))
		if not (len(time) == 8 and 0 <= m < 60 > s >= 0):
			return None
	except ValueError:
		return None
	return h * 3600 + m * 60 + s