When l = 0, you’ll access caches[L] which is incorrect. Pay attention to the reversed construct in the for loop.
l = 0
caches[L]
reversed