Yes, indeed. You can also do that, and other small variations on it depending on the context, with a macro.
You go to the end of "josh", press F3, add a comma and a space and you delete the rest of the line, until "sam" is now the next symbol after your cursor. Then you go to the end of the line (C-e) and press F4. Your macro is now recorded. To call it, press F4 repeatedly until everything is on one line.
As a bonus, you can actually name your macro, assign a keybinding to it, and can also save it as Lisp code.