So I have this code which counts the number of symbols in lists with for cycle, which is not recursion
def cnt_same(l: list, pos=None, res=None) -> dict:
if res is None and pos is None:
res = {}
pos = 1
for i in l:
if not type(i) == list:
res[i] = res.get(i, 0) + pos
else:
cnt_same(i, pos, res)
return res
output:
print(cnt_same([[], [], [], [], ["h", "h", "m"], [], ["m", "m", "M", "m"]])) # {'h': 2, 'm': 4, 'M': 1}
print(cnt_same([])) # {}
print(cnt_same([['a'], 'b', ['a', ['b']]])) # {'a': 2, 'b': 2}
How to turn this code into a recursive solution in which the passage through the lists is done by recursion?