###Instructions

A time period starting from ```'hh:mm'``` lasting until ```'hh:mm'``` is stored in an array:
```
['08:14', '11:34']
```
A set of different time periods is then stored in a 2D Array like so, each in its own sub-array:
```
[['08:14','11:34'], ['08:16','08:18'], ['22:18','01:14'], ['09:30','10:32'], ['04:23','05:11'], ['11:48','13:48'], ['01:12','01:14'], ['01:13','08:15']]
```
Write a function that will take a 2D Array like the above as argument and return a 2D Array of the argument's sub-arrays sorted in ascending order.

Take note of the following:

* The first time period starts at the earliest time  possible ```('00:00'+)```.
* The next time period is the one that starts the soonest **after** the prior time period finishes. If several time periods begin at the same hour, pick the first one showing up in the original array.
* The next time period can start the same time the last one finishes.

This:
```
[['08:14','11:34'], ['08:16','08:18'], ['13:48','01:14'], ['09:30','10:32'], ['04:23','05:11'], ['11:48','13:48'], ['01:12','01:14'], ['01:13','08:15']]
```
Should return:
```
[['01:12','01:14'], ['04:23','05:11'], ['08:14','11:34'], ['11:48','13:48'], ['13:48','01:14'], ['08:16','08:18'], ['09:30','10:32'], ['01:13','08:15']]
```

Difficulty: EASY
Starter code: def sort_time(arr):
	

Solutions:
def sort_time(arr):
	(arr, s) = (sorted(arr, key=lambda t: t[0]), [])
	while arr:
		nextTP = next((i for (i, t) in enumerate(arr) if not s or t[0] >= s[-1][1]), 0)
		s.append(arr.pop(nextTP))
	return s


def sort_time(arr):
	arr = sorted(arr, key=lambda x: x[0])
	out = [['', '00:00']]
	while arr:
		i = next((i for (i, t) in enumerate(arr) if t[0] >= out[-1][1]), None)
		out.append(arr.pop(i if i else 0))
	return out[1:]


def sort_time(arr):
	(arr, prv, result) = (sorted(arr, key=lambda p: p[0]), '00:00', [])
	while arr:
		nxt = next((p for p in arr if p[0] >= prv), arr[0])
		result.append(nxt)
		arr.remove(nxt)
		prv = nxt[1]
	return result


mins = lambda time: (lambda res: int(res[0]) * 60 + int(res[1]))(time.split(':'))
dt = lambda a, b: (lambda diff: 1440 + diff if diff < 0 else diff)(mins(a) - mins(b))
sort_time = lambda arr, last='00:00': [arr[0]] if len(arr) == 1 else (lambda arr: [arr[0]] + sort_time(arr[1:], arr[0][1]))(sorted(arr, key=lambda a: dt(a[0], last)))


from operator import itemgetter

def sort_time(arr):
	L = sorted(arr, key=itemgetter(0))
	result = [L.pop(0)]
	while L:
		result.append(L.pop(next((i for i in range(len(L)) if L[i][0] >= result[-1][1]), 0)))
	return result


from datetime import datetime, timedelta

def delta(*span):
	(start, end) = [datetime.strptime(s, '%H:%M') for s in span]
	return (end + timedelta(days=1) if start > end else end) - start

def sort_time(arr):
	prev = '00:00'
	xs = list(arr)
	result = []
	while xs:
		i = min(enumerate(xs), key=lambda x: delta(prev, x[1][0]))[0]
		(a, prev) = xs.pop(i)
		result.append([a, prev])
	return result


def sort_time(arr):
	if len(arr) == 0:
		return []
	r_max = '23:59'
	r_min = '00:00'
	rr = arr[:]
	ret = []
	k = 0
	for i in range(len(arr)):
		for j in range(len(rr)):
			if r_min <= rr[j][0] < r_max:
				r_max = rr[j][0]
				k = j
				if r_max == r_min:
					break
		ret.append(rr[k])
		r_min = rr[k][1]
		r_max = '23:59'
		rr.pop(k)
		k == 0
		if rr and max(rr)[0] < r_min:
			r_min = min(rr)[0]
	return ret


def sort_time(arr):
	s = sorted(arr, key=lambda x: (x[0], arr.index(x)))
	r = [s.pop(0)]
	while s:
		if r[-1][1] > s[-1][0]:
			r.append(s.pop(0))
			continue
		for i in range(len(s)):
			if r[-1][1] <= s[i][0]:
				r.append(s.pop(i))
				break
	return r


def sort_time(arr):
	arr = arr[:]
	result = []
	next = min(arr)
	while True:
		result.append(next)
		arr.remove(next)
		if not arr:
			break
		next = None
		for t in arr:
			if result[-1][1] <= t[0]:
				if next is None or next[0] > t[0]:
					next = t
		if next is None:
			next = min(arr)
	return result