3 ms·
As he remarks, he doesn't take in account the corner cases. Suprisingly, or maybe not, his concatenation statement is similar to what I regularly use: def co
by Luyt 15y ago
As he remarks, he doesn't take in account the corner cases. Suprisingly, or maybe not, his concatenation statement is similar to what I regularly use:
def commalist(f, endword="and"):
"Concatenate a list of strings in the form of 'Red, Yellow, Green and Blue'."
if len(f) == 0:
return ""
elif len(f) == 1:
return f[0]
else:
return ", ".join(f[:-1]) + " " + endword + " " + f[-1]