So basically, I use Python, a popular programming language. There’s this one problem that I just don’t understand why happening. I’m learning " Accessing 2D lists in Python" which my code was like:
you missed commas between the inner lists’ elements. Each inner list should be separated by a comma to distinguish one list from another within the main list
I would not get too hung up on this. You have an error in a two line program and the print statement is very simple. You can see there is no syntax error there.
There is a concept called “traceback” where you might get an error in a statement but it’s caused by a previous statement and you need to “trace back” to what caused the error. Sometimes you will get a more detailed traceback error that follows the error to it’s source.
Not sure what you are using to code, but I put this program into Google Collab and it shows this error:
File "<ipython-input-1-875ad81545af>", line 1
class_name_test = [["Jenny", 90] ["Alexus", 85.5 ["Sam", 83] ["Ellie",101.5]]
^
SyntaxError: '[' was never closed
It might be more helpful. In any case if you look closely at your array, you are clearly missing a bracket. Make it easier to look at:
I fixed the error in Alexus list then,
the terminal:
Traceback (most recent call last):
File "script.py", line 3, in <module>
["Alexus", 85.5]
TypeError: list indices must be integers or slices, not tuple
What you have here is a nested list. A list within a list. All list elements have a comma between them. ["Jenny", 90] Here is a list with two elements. It’s contained within a list of lists. Now that “outside list” I do not see commas