This is the fixed version of your code:
def list_to_string2(values, num=""):
s = str(values[0])
if len(values) == 1:
return num + s
else:
num += s + ", "
return list_to_string2(values[1:], num)
If you don't want recursion, you can simply do the following code:
def list_to_string2(values):
return ", ".join(map(str, a))
If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch