Imagine a funnel filled with letters. The bottom letter drops out of the funnel and onto a conveyor belt:

```
  \b,c/  -->   \b,c/
   \a/   -->    \ /
                 a
-------     -------
```
If there are two letters above a gap, the smaller letter falls into the gap.
```
  \b,c/   -->   \  c/ 
   \ /    -->    \b/   
a            a         
-------      -------
```
Of course, this can create a new gap, which must also be filled in the same way:
```
  \f,e,d/  -->  \f, ,d/
   \  c/   -->   \e,c/ 
    \b/           \b/   
   a            a         
  -------      -------
```
Once all the gaps above it have been filled, the bottom letter drops out of the funnel and onto the conveyorbelt. The process continues until all letters have fallen onto the conveyor. (New letters fall onto the end of the existing string)

**KATA GOAL: Return the string on the conveyorbelt after all letters have fallen**.
```
\f, ,d/      \f, ,d/   --> etc -->    \     /
 \e,c/        \e,c/    --> etc -->     \   /
  \b/    -->   \ /     --> etc -->      \ /
a           a   b                   abcdef
-------     -------                 -------
```
All letters in the funnel will be unique i.e. in every comparison one letter will be strictly smaller than the other. The funnel will be presented as a nested list, e.g:
```
[["d","a","c"],
   ["b","e"],
     ["f"]]
```
The value of a letter is defined by its codepoint. Note: this means all capital letters are defined as smaller than all lower-case letters, but your language's comparison operator will probably treat it that way automatically.

The funnels will always be "nice" -- every layer will have 1 item more than the layer below, and every layer will be full, and generally there's no funny business or surprises to consider. The only characters used are standard uppercase and lowercase letters A-Z and a-z. The tests go up to 9 layer funnel.

### Fully Worked Example
```
\d,a,c/      \d,a,c/      \d,a,c/ -->  \d   c/     
 \b,e/        \b,e/  -->   \  e/  -->   \a,e/
  \f/   -->    \ /   -->    \b/          \b/  --> 
                f        f            f
------      -------      -------      -------


\d   c/      \d   c/ -->  \    c/      \    c/     
 \a,e/  -->   \  e/  -->   \d,e/        \d,e/  -->
  \ /   -->    \a/          \a/   -->    \ /   -->
f  b        fb           fb           fb  a
------      -------      -------      -------


 \    c/      \    c/      \    c/ -->  \     /     
  \  e/        \  e/  -->   \   /  -->   \  c/   
   \d/   -->    \ /   -->    \e/          \e/  -->
fba          fba d       fbad          fbad
-------      -------     --------      -------


  \     /      \     /      \     /
   \  c/  -->   \   /        \   / 
    \ /          \c/   -->    \ /   
fbad e       fbade        fbadec         
-------      -------      -------

DONE. Return "fbadec".

```

**For a bigger funneling challenge, check out [this kata](https://www.codewars.com/kata/create-a-funnel) by @myjinxin2015.**

Difficulty: EASY
Starter code: def funnel_out(funnel):
	

Solutions:
def funnel_out(funnel):
	r = ''
	h = len(funnel)
	while funnel[h - 1][0] != '~':
		r += funnel[h - 1][0]
		funnel[h - 1][0] = '~'
		i = h - 1
		j = 0
		while i > 0:
			if funnel[i - 1][j] < funnel[i - 1][j + 1]:
				funnel[i][j] = funnel[i - 1][j]
				funnel[i - 1][j] = '~'
			else:
				funnel[i][j] = funnel[i - 1][j + 1]
				funnel[i - 1][j + 1] = '~'
				j += 1
			i -= 1
	print(funnel)
	return r


def funnel_out(funnel):
	if not funnel:
		return ''
	ret = []
	while funnel[-1][-1]:
		j = 0
		ret.append(funnel[-1][j])
		funnel[-1][j] = None
		for i in range(-2, -len(funnel) - 1, -1):
			(_, k) = min(((funnel[i][x] or 'ÿ', x) for x in (j, j + 1)))
			(funnel[i + 1][j], funnel[i][k], j) = (funnel[i][k], funnel[i + 1][j], k)
	return ''.join(ret)


def pull_letter(funnel):
	letter = funnel[0][0]
	funnel[0][0] = None
	pos = 0
	for (idx, level) in enumerate(funnel[:-1]):
		current_pos = pos
		c1 = funnel[idx + 1][pos]
		c2 = funnel[idx + 1][pos + 1]
		if c1 is None or (c2 is not None and c1 >= c2):
			pos += 1
		level[current_pos] = funnel[idx + 1][pos]
		funnel[idx + 1][pos] = None
	return letter

def funnel_out(funnel):
	funnel = list(reversed(funnel))
	result = ''
	while funnel[0][0]:
		result += pull_letter(funnel)
	return result


def drop(p):
	p[0][0] = ''
	x = 0
	for y in range(1, len(p)):
		dx = 1 if not p[y][x] else 0 if not p[y][x + 1] else 1 if p[y][x + 1] < p[y][x] else 0
		p[y - 1][x] = p[y][x + dx]
		x += dx
	p[-1][x] = ''

def funnel_out(funnel):
	s = []
	p = [r[:] for r in reversed(funnel)]
	while p[0][0]:
		s.append(p[0][0])
		drop(p)
	return ''.join(s)


from copy import deepcopy

def funnel_out(funnel):
	(funnel, ans, depth) = (deepcopy(funnel), [], len(funnel))
	for _ in range(depth * (depth + 1) // 2):
		ans.append(funnel[-1][0])
		(i, funnel[-1][0]) = (0, '~')
		for d in range(depth - 1, 0, -1):
			iUp = min((i, i + 1), key=lambda x: funnel[d - 1][x])
			if funnel[d - 1][iUp] == '~':
				break
			(funnel[d][i], funnel[d - 1][iUp]) = (funnel[d - 1][iUp], funnel[d][i])
			i = iUp
	return ''.join(ans)


def funnel_out(funnel):
	(break_outs, n) = ([], len(funnel))
	while len(break_outs) < n * (n + 1) / 2:
		break_outs.append(funnel[-1][0])
		(funnel[-1][0], prev) = ('~', 0)
		for i in range(len(funnel) - 1, 0, -1):
			m = min(funnel[i - 1][prev:prev + 2])
			index = funnel[i - 1].index(m)
			(funnel[i - 1][index], funnel[i][prev], prev) = ('~', m, index)
	return ''.join(break_outs)


def funnel_out(funnel):
	ans = ''
	while funnel[-1][0] != '~':
		ans += funnel[-1][0]
		(i, funnel[-1][0]) = (0, '~')
		for d in range(len(funnel) - 1, 0, -1):
			iUp = min((i, i + 1), key=lambda x: funnel[d - 1][x])
			(funnel[d][i], funnel[d - 1][iUp]) = (funnel[d - 1][iUp], funnel[d][i])
			i = iUp
	return ans


def funnel_out(lst):
	ans = ''
	while lst != [[]]:
		temp = []
		for i in range(len(lst) - 1, -1, -1):
			x = lst[i]
			x2 = lst[i - 1]
			if i == len(lst) - 1:
				ans += x[0]
				if len(lst) == 1:
					lst = [[]]
					break
				lst[i] = [min([k for k in x2 if k != ''])] if len(lst) > 1 else []
				lst[i - 1][x2.index(min([k for k in x2 if k != '']))] = ''
			elif i == 0:
				if all((j == '' for j in lst[0])):
					lst = lst[1:]
				else:
					break
			else:
				for j in range(len(x)):
					if x[j] == '':
						(a, b) = (x2[j], x2[j + 1])
						t = [k for k in (a, b) if k != '']
						val = min(t) if t != [] else ''
						idx = j if x2[j] == val else j + 1
						x[j] = val
						x2[idx] = ''
	return ans


def funnel_out(funnel):
	ans = ''
	while funnel:
		ans += funnel[-1].pop()
		funnel[-1].append('µ')
		for row in range(len(funnel) - 1, 0, -1):
			for col in range(len(funnel[row])):
				if funnel[row][col] == 'µ':
					if funnel[row - 1][col] < funnel[row - 1][col + 1]:
						funnel[row][col] = funnel[row - 1][col]
						funnel[row - 1][col] = 'µ'
					else:
						funnel[row][col] = funnel[row - 1][col + 1]
						funnel[row - 1][col + 1] = 'µ'
			if all((en == 'µ' for en in funnel[row])):
				del funnel[row]
		if len(funnel) == 1:
			break
	return ans


def funnel_out(funnel):
	(result, funnel) = ([], funnel[::-1])

	def move(i=0, j=0):
		if i < len(funnel) - 1:
			(c1, c2) = funnel[i + 1][j:j + 2]
			if c1 and (not c2 or c1 < c2):
				funnel[i][j] = c1
				return move(i + 1, j)
			elif c2 and (not c1 or c2 < c1):
				funnel[i][j] = c2
				return move(i + 1, j + 1)
		funnel[i][j] = ''
	while funnel[0][0]:
		result.append(funnel[0][0])
		move()
	return ''.join(result)