class QuotedList extends ArrayList<String> {
String d, q;
QuotedList(String d, String q) {
this.d = d;
this.q = q;
}
public boolean add(String s) {
if (s.contains(" ")) s = q + s + q;
return super.add(s);
}
public String toString() {
return join(d, this);
}
}
QuotedList x = new QuotedList(d, q) {{
for (var x : a) add(x);
}};
String s = x.toString();
class QuotedList(list):
def __init__(self, quotes, sep):
super().__init__()
self.quotes = quotes
self.sep = sep
def append(self, value):
if ' ' in value:
value = value.join(self.quotes)
super().append(value)
def extend(self, iterable):
for value in iterable:
self.append(value)
def __str__(self):
return self.sep.join(self)
qlist = QuotedList(q * 2, d)
qlist.extend(a)
s = str(qlist)