Python Forum

Full Version: How to check if my argument is a tuple with 3 tuples
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I have this function that will tell me if my argument is a tuple with 3 tuples in it, each of them with 3 digits.
so I'm using a lot of ifs, isinstances and for to do it, something like this:

def f(x):

if isinstance(x, tuple) and len(x) == 3:
____for item in x:
________if isinstance(item, tuple) and len(item) == 3:
______________for i in item:
___________________(code to check check values)
_________________________return True
This however is not working ecause I believe the code isn't going over all items and after the first i from the first item, if it checks out it just returns True. Is this the problem?
(Nov-15-2020, 06:13 PM)zarox Wrote: [ -> ]Is this the problem?

Yes, it looks like you’re correct, at the first opportunity it will return True. Rather than returning True when the condition is met, you can change it to return False if the condition is not met. Then, finally at the end of the function, you can return True if none of the checks failed.