我有一个序列urls = spam, eggs, foo, bar
,我想将它们格式化为'blogs “spam”, “eggs”, “foo”, and “bar” are not owned by primary “monty”'
之类的字符串。
现在有很多低效的方法我可以想到实现这个目标,但最蟒蛇的是什么?现在我有
'blogs {0}, and “{1}” are not owned by primary “{primary}”'.format(
', '.join('“' + url + '”' for url in urls[:-1]), urls[-1], primary='monty')
感觉很笨,当然不适用于len(urls)
< 3
。