Convert for loop to lambda