Liste içinde kaç liste var?

def total_sublists(arg: list, count=0):
    prev_count = count
    next_list = []
    for i in arg:
        if isinstance(i, list):
            count += 1
            next_list += [*i]
    if prev_count == count:
        return count
    return total_sublists(next_list, count)
print(total_sublists([[1, 2, 3, [1, 2, 3, 4, [1, 2, 3, 4, 5]]], [1, 2, 3], "a", 1, 2, [1, [1, 2]]]))
>> 6

Bu şekilde, bir recursive function ile çözebildim ama umarım recursive function’ların standardına/doğasına aykırı bir şey yapmamışımdır :D Zira Recursion’larla pek alakam olmadı şimdiye kadar.

4 Beğeni