This error occurs when we try to use a string (or any non-integer type) in place of integer or index when trying to extract an element from a list.
Example:
main.py46 chars3 lines
Output:
main.py60 chars2 lines
To resolve this error we need to use integers or slices as indices to extract elements from the list.
Example:
main.py44 chars3 lines
Output:
main.py2 chars2 lines
We can also use a variable that holds an integer value for indexing.
Example:
main.py58 chars4 lines
Output:
main.py2 chars2 lines
gistlibby LogSnag