该表达式可以做到:
print ", ".join(data[:-2] + [" and ".join(data[-2:])])
如此处所示:
>>> data
['foo', 'bar', 'baaz', 'bah']
>>> while data:
... print ", ".join(data[:-2] + [" and ".join(data[-2:])])
... data.pop()
...
foo, bar, baaz and bah
foo, bar and baaz
foo and bar
foo