In this kata, you will do addition and subtraction on a given string. The return value must be also a string.

**Note:** the input will not be empty.

## Examples

```
"1plus2plus3plus4"  --> "10"
"1plus2plus3minus4" -->  "2"
```

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def calculate(s):
	

Solutions:
def calculate(s):
	return str(sum((int(n) for n in s.replace('minus', 'plus-').split('plus'))))


calculate = lambda s: str(eval(s.replace('plus', '+').replace('minus', '-')))


def calculate(s):
	return str(eval(s.replace('plus', '+').replace('minus', '-')))


def calculate(s):
	oper = []
	for c in s:
		if c == 'p':
			oper.append('+')
		if c == 'm':
			oper.append('-')
	s = s.replace('plus', ' ')
	s = s.replace('minus', ' ')
	s = s.split(' ')
	result = int(s[0])
	for i in range(len(oper)):
		if oper[i] == '+':
			result += int(s[i + 1])
		else:
			result -= int(s[i + 1])
	return str(result)


def calculate(s):
	t = s.replace('plus', '+')
	y = t.replace('minus', '-')
	return str(eval(y))


def calculate(s):
	return str(sum(map(int, s.replace('plus', ' ').replace('minus', ' -').split())))


import re

def calculate(s):
	xs = re.split('(plus|minus)', s)
	xs[::2] = map(int, xs[::2])
	return str(xs[0] + sum((xs[i + 1] * (1 if xs[i] == 'plus' else -1) for i in range(1, len(xs), 2))))