How to concatenate a Python dictionary to display all the values together?


You can get all the values using a call to dict.values(). Then you can call ", ".join on the values to concatenate just the values in the dict separated by commas. 

example

a = {'foo': "Hello", 'bar': "World"}
vals = a.values()
concat = ", ".join(vals)
print(concat)

Output

This will give the output −

Hello, World

Updated on: 05-Mar-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements