Q:

How do I transform a list into an equation?

So, I've been trying to make an advanced calculator many ways and this is the best I could think of:
operation = str(input('Operation:'))

operation_list = operation.split(' ')

for i in range(len(operation_list)):
    if operation_list[i] not in '+-/*':
        operation_list[i] = int(operation_list[i])

print(operation_list)

This code will transform every number in the str into an int and put everything in a list:
Operation: 10 + 10 + 10

Terminal: [10, '+', 10, '+', 10]

I don't know if it is possible to do that, but I want to transform that list like it was an actual equation.
Anyone got any ideas?

A:

Solution: Use python's built-in eval()
operation = input('Operation: ')  # input() always returns string, no need to convert
print(eval(operation))

Operation: 5 * 10 + 2
52

Note, you may want to confirm the user entered a valid equation. Malicious users might do something like this: https://medium.com/swlh/hacking-python-applications-5d4cd541b3f1.

