Refactoring the iteration/output operation to one line