Write a simple parser that will parse and run Deadfish.  

Deadfish has 4 commands, each 1 character long:
* `i` increments the value (initially `0`)
* `d` decrements the value
* `s` squares the value
* `o` outputs the value into the return array

Invalid characters should be ignored.

```python
parse("iiisdoso")  ==>  [8, 64]
```

Difficulty: EASY
Starter code: def parse(data):
	

Solutions:
def parse(data):
	value = 0
	res = []
	for c in data:
		if c == 'i':
			value += 1
		elif c == 'd':
			value -= 1
		elif c == 's':
			value *= value
		elif c == 'o':
			res.append(value)
	return res


def parse(data):
	action = {'i': lambda v, r: v + 1, 'd': lambda v, r: v - 1, 's': lambda v, r: v * v, 'o': lambda v, r: r.append(v) or v}
	(v, r) = (0, [])
	for a in data:
		v = action[a](v, r) if a in action else v
	return r


COMMANDS = {'i': lambda x: x + 1, 'd': lambda x: x - 1, 's': lambda x: x * x}

def parse(data):
	(result, x) = ([], 0)
	for c in data:
		if c == 'o':
			result.append(x)
		elif c in COMMANDS:
			x = COMMANDS[c](x)
	return result


class Deadfish:
	commands = {'i': lambda df: df.i(), 'd': lambda df: df.d(), 's': lambda df: df.s(), 'o': lambda df: df.o()}

	def __init__(self):
		self.value = 0
		self.outputs = []

	def i(self):
		self.value += 1

	def d(self):
		self.value -= 1

	def s(self):
		self.value **= 2

	def o(self):
		self.outputs.append(self.value)

	def apply(self, command):
		try:
			Deadfish.commands[command](self)
		except KeyError:
			pass

def parse(commands):
	df = Deadfish()
	[df.apply(c) for c in commands]
	return df.outputs


def parse(data):
	(v, r) = (0, [])
	for c in data:
		(v, r) = (v + {'i': 1, 'd': -1, 's': v * (v - 1)}.get(c, 0), r + [v] * (c == 'o'))
	return r


def parse(data):
	result = []
	value = 0
	for command in data:
		if command == 'i':
			value += 1
		elif command == 'd':
			value -= 1
		elif command == 's':
			value = value ** 2
		elif command == 'o':
			result.append(value)
	return result


def parse(data):

	def process_char(c):
		nonlocal v
		if c == 'i':
			v += 1
		elif c == 'd':
			v -= 1
		elif c == 's':
			v *= v
		elif c == 'o':
			return True
	v = 0
	return [v for c in data if process_char(c)]


def parse(s):
	ans = []
	num = 0
	for c in s:
		if c == 'i':
			num += 1
		if c == 'd':
			num -= 1
		if c == 's':
			num **= 2
		if c == 'o':
			ans.append(num)
	return ans


def parse(data):
	curr = 0
	output = []
	for cmd in data:
		if cmd == 'i':
			curr += 1
		elif cmd == 'd':
			curr -= 1
		elif cmd == 's':
			curr *= curr
		elif cmd == 'o':
			output.append(curr)
	return output