大多数Pythonic将序列格式化为字符串的方法?

时间:2016-07-24 02:14:07

标签: python string-formatting

我有一个序列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

0 个答案:

没有答案