def conta(tupla, string, total = 0):
if type(tupla) in [list, tuple]:
for item in tupla:
total = conta(item, string, total)
else:
total += str(tupla).count(string)
return total
tupla1=("foi",)
tupla2=([1,2,3],[['onde',2.3], 'oi',78], ['a', 'b', 'c'])
tupla2=([1,2,3],(('onde',2.3), 'oi',78), ['a', 'b', 'c'])
tupla3=([1,2,3],(('onde', 'noiva',2.3), 'oi',78), ['a', 'b', 'c'])
tupla4=(('MAO', 'MOA') , 13.8 , 'c' , 6 , [2,3])
resultado1=conta(tupla1,"oi")
resultado2=conta(tupla2,"oi")
resultado3=conta(tupla3,"oi")
resultado4=conta(tupla4,"oi")
print("Retorna ",resultado1)
print("Retorna ",resultado2)
print("Retorna ",resultado3)
print("Retorna ",resultado4)
ZGVmIGNvbnRhKHR1cGxhLCBzdHJpbmcsIHRvdGFsID0gMCk6CgogICAgaWYgdHlwZSh0dXBsYSkgaW4gW2xpc3QsIHR1cGxlXToKICAgICAgICBmb3IgaXRlbSBpbiB0dXBsYToKICAgICAgICAgICAgdG90YWwgPSBjb250YShpdGVtLCBzdHJpbmcsIHRvdGFsKQogICAgZWxzZToKICAgICAgICB0b3RhbCArPSBzdHIodHVwbGEpLmNvdW50KHN0cmluZykKICAgICAgICAgICAgCiAgICByZXR1cm4gdG90YWwKCnR1cGxhMT0oImZvaSIsKQp0dXBsYTI9KFsxLDIsM10sW1snb25kZScsMi4zXSwgJ29pJyw3OF0sIFsnYScsICdiJywgJ2MnXSkKdHVwbGEyPShbMSwyLDNdLCgoJ29uZGUnLDIuMyksICdvaScsNzgpLCBbJ2EnLCAnYicsICdjJ10pCnR1cGxhMz0oWzEsMiwzXSwoKCdvbmRlJywgJ25vaXZhJywyLjMpLCAnb2knLDc4KSwgWydhJywgJ2InLCAnYyddKSAKdHVwbGE0PSgoJ01BTycsICdNT0EnKSAsIDEzLjggLCAnYycgLCA2ICwgWzIsM10pIAoKcmVzdWx0YWRvMT1jb250YSh0dXBsYTEsIm9pIikKcmVzdWx0YWRvMj1jb250YSh0dXBsYTIsIm9pIikKcmVzdWx0YWRvMz1jb250YSh0dXBsYTMsIm9pIikKcmVzdWx0YWRvND1jb250YSh0dXBsYTQsIm9pIikKCnByaW50KCJSZXRvcm5hICIscmVzdWx0YWRvMSkKcHJpbnQoIlJldG9ybmEgIixyZXN1bHRhZG8yKQpwcmludCgiUmV0b3JuYSAiLHJlc3VsdGFkbzMpCnByaW50KCJSZXRvcm5hICIscmVzdWx0YWRvNCk=