match len(a):
case 1:
s = a[0]
case 2:
s = ' and '.join(a)
case _:
s = ', '.join(a[:-1])
s += ', and ' + a[-1]
class ListFormatter(dict):
def set(self, *i, left='', right=''):
self[i] = left, right
def format_list(self, array):
a = list(map(str, array))
for key, values in self.items():
for i in key:
a[i] = a[i].join(values)
return ''.join(a)
x = ListFormatter()
match n := len(a):
case 1: ...
case 2: x.set(0, right=' and ')
case _:
x.set(*range(n - 1), right=', ')
x.set(-1, left='and ')
s = x.format_list(a)
int n {size(a)};
string s;
if (n == 1) s = a[0];
else if (n == 2)
s = a[0] + " and "s + a[1];
else {
int i {};
s = a[i++];
--n;
while (i not_eq n)
s += ", "s + a[i++];
s += ", and "s + a[n];
}
int n = a.length - 1;
String s = switch (n) {
case 0 -> a[0];
case 1 -> a[0] + " and " + a[1];
default -> {
s = join(", ", copyOfRange(a, 0, n));
yield s + ", and " + a[n];
}
};
String s = format("{0,list}", a);
if Length(a) > 1 then
begin
s := String.Join(', ', a, 0, Length(a)-1);
s := s + ' and ' + a[High(a)]
end
else
begin
if Length(a) > 0 then
s := a[0]
else
s :='';
end;
remainder, last = a[..-2], a[-1]
s = remainder.join(", ") + "#{' and ' unless remainder.empty?}" + last.to_s
let s = match a.len() {
0 => String::new(),
1 => a[0].to_string(),
2 => format!("{} and {}", a[0], a[1]),
n => {
let mut r = String::new();
for i in 0..n - 1 {
write!(r, "{}, ", a[i]).unwrap();
}
write!(r, "and {}", a[n - 1]).unwrap();
r
}
};