#C6377. MATLAB Array to Nested List Conversion
MATLAB Array to Nested List Conversion
MATLAB Array to Nested List Conversion
Given a string that represents a MATLAB-style array initialization, your task is to convert it into a nested list (i.e. a list of lists). The input string is enclosed within square brackets and includes numerical values separated by spaces and/or commas, with rows separated by semicolons. For example, the input "[1 2 3; 4 5 6]" should be converted to [[1, 2, 3], [4, 5, 6]].
Be careful to handle extra spaces and the mixed use of commas and spaces as delimiters. If the input is an empty array (i.e. "[]"), output an empty list. You may use ( \LaTeX ) in formulas if necessary.
inputFormat
The input consists of a single line from standard input (stdin) containing a MATLAB-style array initialization string. This string is enclosed in square brackets and may contain numbers separated by spaces or commas, with rows separated by semicolons.
outputFormat
Output the nested list in a Python-like list format. For example, if the input is "[1 2 3; 4 5 6]", the output should be "[[1, 2, 3], [4, 5, 6]]", printed to standard output (stdout).## sample
[1 2 3; 4 5 6; 7 8 9]
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]