refactor use of for-loop

Instead of iterating over a list and appending all elements to another list
one-by one we use extend to join the two lists.