使用dict设置Python字符串格式

使用dict设置Python字符串格式,python,Python,我对python相当陌生,迄今为止,我所做的所有搜索都无法找到答案。如果已经回答了这个问题,请给我指出正确的方向。详情如下: 我有以下柜台: Counter({'storage': 3, 'control': 1}) 格式如下: print "Duplicate IP, {0}, found on {1} nodes.".format(a," and ".join("%s %s" % (c,n) for n,c in dict(counter).items())) 这将产生: Duplica

我对python相当陌生,迄今为止,我所做的所有搜索都无法找到答案。如果已经回答了这个问题,请给我指出正确的方向。详情如下:

我有以下柜台:

Counter({'storage': 3, 'control': 1})
格式如下:

print "Duplicate IP, {0}, found on {1} nodes.".format(a," and ".join("%s %s" % (c,n) for n,c in dict(counter).items()))
这将产生:

Duplicate IP, 192.168.56.20, found on 1 control and 3 storage.
是否有办法增强此功能,使计数为1时不显示“1”?i、 e:

Duplicate IP, 192.168.56.20, found on control and 3 storage nodes.
任何帮助都将不胜感激

print "Duplicate IP, {0}, found on {1} nodes.".format(a," and ".join("%s %s" % (c if c > 1 else '',n) for n,c in dict(counter).items()))
如果c不大于1,则追加空字符串