The function doesn't use anymore 'map', 'filter' and 'os.path.realpath' + it's based on a single loop.