Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for How Deep by dig
def istuple(tupla):
llista=[]
for element in tupla:
if type(element)!=tuple:
llista.append(element)
else:
for i in element:
llista.append(i)
return llista
def single_tuple(tupla):
for i in tupla:
if type(i)==tuple: return False
return True
def how_deep(structure: tuple) -> int:
a, count=False, 0
while a==False:
count+=1
a=single_tuple(structure)
structure=istuple(structure)
return count
print("Example:")
print(how_deep((1, 2, 3)))
# These "asserts" are used for self-checking
assert how_deep((1, 2, 3)) == 1
assert how_deep((1, 2, (3,))) == 2
assert how_deep((1, 2, (3, (4,)))) == 3
assert how_deep(()) == 1
assert how_deep(((),)) == 2
assert how_deep((((),),)) == 3
assert how_deep((1, (2,), (3,))) == 2
assert how_deep((1, ((),), (3,))) == 3
print("The mission is done! Click 'Check Solution' to earn rewards!")
Feb. 15, 2023