Try this, it takes into consideration the edge cases and uses format(), to show another possible solution:
def my_join(lst):
if not lst:
return ""
elif len(lst) == 1:
return str(lst[0])
return "{} and {}".format(", ".join(lst[:-1]), lst[-1])
Works as expected:
my_join([])
=> ""
my_join(["x"])
=> "x"
my_join(["x", "y"])
=> "x and y"
my_join(["x", "y", "z"])
=> "x, y and z"