I have a dictionary:
self.currently_occupied = {obj:[0, 0]}
I need to check if the value of obj contains anything other than two numbers in a list
Example:
obj:[58, -234] is ok
obj:[32] is not
obj:[] is not
obj:[4, k] is not
My solution is to large extent based on @Levon’s solution, but I am adding one more detail. Just using is
isinstancecan lead some lists that are not composed of numbers to qualify. For example:would qualify because technically both above values are
float; however, they are not numbers; therefore we need to add an additional condition to control for that.Result:
EDIT:
I think the use of
isfinitemakes the code cleaner, and I also think that we don’t need to useisinstancein this case. The resulting code would be: