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

PythonProgramming

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
raja
Published on 18-Apr-2018 12:56:32
Advertisements