+ 1

How can I improve my commacode?

def list_value(*spam, sep=','): li =list(*spam) return sep.join(li) li=list_value(input()) l='{} and {}'.format((li[:-1),(li[-1])) print(list_value(l)) just help me fix my code, so I could have the expected result. I have no idea what mess I have created, that the output is so obscure. if input: ['apple', 'banana', 'mango'] expected output: 'apple, banana, and mango'

22nd Apr 2018, 3:14 PM
Tincture
1 Answer
+ 9
def deco (list): res = "" [(res = res + el + ", ") for el in list[:-1]] return res + "and " + str (list[-1])
22nd Apr 2018, 3:50 PM
Rull Deef đŸș
Rull Deef đŸș - avatar