Note: This problem is not specific to any one lesson, but just an issue I encountered while doing some random coding.
My goal was to print the individual values of a list within another list, without using the
list[index], thus the program should figure out on its own which elements within the list are its own list.
hi = [17,8,[4,5,1]] for variable in hi: print variable if isinstance (variable, list): print hi[hi.index(variable)] else: print "False"
This returns an error:
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types
This Error really surprised me, as I thought
list is a datatype (also suggested to be true here: https://docs.python.org/2/library/datatypes.html)
See below another very similar piece of code which also didn’t function due to the same Error, which I found online (can’t find the exact source anymore):
isinstance(, list) >>> True
At least, that’s what the most voted commentor on StackOverflow said it would do. All it gives me is the same Error.
What is causing this issue? what would be a solution to it?
I understand that the structure of the lists within list is not very elegant and probably confusing in any practical application, thus that it should be avoided.
Edit: I also understand that even with this error fixed my code would not be fully functional yet.