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?

sam
  • 203
  • 1
  • 3
  • 15

1 Answers1

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}')
bigbounty
  • 16,526
  • 5
  • 37
  • 65