Question: In python, how do you create an array of unknown dimensional size? I want to create an array of unknown dimensional size based on a
In python, how do you create an array of unknown dimensional size?
I want to create an array of unknown dimensional size based on a number I recieve. To elaborate, let's say n = 2, it will output a 3D array {true, true, true}. If n = 3, then its output will be a 4D array {true, true, true, true}. Whatever the n value is, the return value will be an array of n + 1 dimensional size. How would I do this? (the hint i'm given says I could also use recursion if I wanted)

The function I'm working on is a truth table generator. I'm given an expression ('a and b') which extracts the variables and returns a truth table as a multidimensional list. Since there are 2 variables, the return value will be a 3D list. {a value, b value, result value}
| a | b | a and b |
| 1 | 1 | 1 |
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 0 |
Return value for the table above would be {{1, 1, 1},{1, 0, 0}, {0, 1, 0},{0, 0, 0}}. The format is {a value, b value, result}.

However, my function is supposed to account for complex expressions as well. Like this ('a and (b |implies| c)'). Since there are 3 variables, my return value should be a 4D list. {{1,1,1,1},{1,1,0,0}, ... , {0,0,0,0}}.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
