def multimap(value, f, count):
    for _ in range(count):
        value = f[value]
yield value
print(list(multimap('a', {'a': 'b', 'b': 'c', 'c': 'd', 'd': 'a'}, 4)))
Multi-mapping a value while saving intermediate values