Turning Dictionary to String

You can create a list of strings(adding variables using f string) and then use join to join them together

my_dict = {1:2, 2:3, 3:4}
my_str = ", ".join([f'{k} {v}' for k,v in my_dict.items()])
1 2, 2 3, 3 4

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top