Replace iterator function with list iteration