1

I am fairly new to python and with all the searching I have done thus far I am unable to find an answer. If this has been answered please point me in the right direction. Here are the details:

I have the following counter:

Counter({'storage': 3, 'control': 1})

The formatting is as follows:

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

which yields:

Duplicate IP, 192.168.56.20, found on 1 control and 3 storage.

Is there a way to enhance this such that if the count is 1 the '1' is not displayed? i.e:

Duplicate IP, 192.168.56.20, found on control and 3 storage nodes.

Any help would be appreciated.

1 Answer 1

3
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()))

appending empty string if c is not greater than 1

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.