def recursive_iterator(iterable):
    for item in iterable:

        # directly iterable types:
        if type(item) in (list, tuple, set, frozenset):
            for child_item in recursive_iterator(item):
                yield child_item

        # other iterable types where we do not want to iterate over the item directly:
        elif type(item) in (dict,):
            for child_item in recursive_iterator(item.values()):
                yield child_item

        # not iterable types which we want to return as they are:
        else: 
            yield item


f = (3, 4, 5, {3: 4}, [16, 7, 8])
g = (1, 2, [3, 4, [5, 6], {7: 8}], 9, 10, {11: f}, {12: [1, 2, {3, 4}, [5, 6]]})

for x in recursive_iterator(g):
    print(x, end=" ")