Given a list containing numbers and arithmetic operators, the task is to solve the list.
Input: lst = [2, '+', 22, '+', 55, '+', 4] Output: 83 Input: lst = [12, '+', 8, '-', 5] Output: 15
Below are some ways to achieve the above tasks.
Method #1: Using Iteration
We can use iteration as the simplest approach to solve the list with importing different operators.
Initial list [91, '+', 132, '-', 156, '+', 4] Answer after solving list is: 71.0
Method #2: Using eval and join
Initial list [2, '+', 22, '+', 55, '+', 4] Answer after solving list is: 83
- Python | sympy.solve() method
- Python | Numbers in a list within a given range
- Python | Convert Stream of numbers to list
- Python | Multiply all numbers in the list (4 different ways)
- Python program to print even numbers in a list
- Python program to count Even and Odd numbers in a List
- Python | Check if list contains consecutive numbers
- Python | Extract numbers from list of strings
- Python - Get summation of numbers in string list
- Python | Create list of numbers with given range
- Python | Largest number possible from list of given numbers
- Python program to print odd numbers in a List
- Python | Sort list of numbers by sum of their digits
- Python | Make a list of intervals with sequential numbers
- Python | Embedded Numbers Summation in String List