Very simple and quick question. Take this list for example:
a = ['hello1', 'hello2', 'hello3']
','.join(a)
I would like to have 'and' instead of a comma before the last element of the list. So I would get:
hello 1, hello 2 and hello 3
instead of....
hello 1, hello 2, hello 3
Is there a way to accomplish this using .join()? I know I can just type it in the list for a simple example like this, but the list I need in my actual program comes from user input.
', '.join(a[:-1]) + 'and ' + a[-1]might be your best bet. There is no builtin function that does this.