Test if the argument is a list or similar, if yes, recurse into it, if not, try to convert it to an integer:
def object_sum(*args):
result = 0
for arg in args:
arg_type = type(arg)
if arg_type in (list, tuple, set, range):
result += object_sum(*arg) # The asterisk is important - without it, the recursively called function would again call itself, and we'd get a RecursionError
else:
try:
result += int(arg) # Try to convert to int
except ValueError:
pass # arg is not convertable, skip it
return result
print(object_sum(3, 'sun', '5', ['5', 'earth'], (5, '5')))
Output:
23