0

I have a dictionary like this

verdict = {'1': 'PASS', '2': 'FAIL}

I want to print this dictionary in a string format without using for loop. output:

1: PASS
2: FAIL

So far I have tried this:

print(*verdict.items(), sep='\n')

Output:
('1', 'PASS')
('2', 'FAIL)

but not getting the actual results

Is there any way through which I can achieve the desired output?

3
  • What have you tried so far? Commented Feb 19, 2021 at 5:46
  • have edited the question. Kindly check. Commented Feb 19, 2021 at 5:47
  • 1
    Not everything can be done with just print() you will need a loop and string formatting (f-string or .format()). Commented Feb 19, 2021 at 5:48

1 Answer 1

1

There are 2 ways I can think of doing this

Method 1:

print("\n".join([f'{k}: {v}' for k, v in verdict.items()]))

Method 2:

for k, v in verdict.items():
    print(f'{k}: {v}')
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.