I have a working function and I would like to improve it to be more efficient. I want to shorten the last two for loops into one loop, but I don\'t know how. The only way I