class List:
def __init__(self):
self.m = []
def apply(self, /, *x, y='', z=''):
self.m.append((x, y, z))
def parse(self, x):
x = [*map(str, x)]
for a, y, z in self.m:
for i in a: x[i] = y + x[i] + z
return ''.join(x)
x = List()
match n := len(a):
case 1: ...
case 2: x.apply(0, z=' and ')
case _:
x.apply(*range(n - 1), z=', ')
x.apply(-1, y='and ')
s = x.parse(a)