so I wanna turn a dictionary to str with keys and values of "10: 2, 8: 1, 12: 5" and to have space and comma separate them like "10 2, 8 1, 12 5"
so I wanna turn a dictionary to str with keys and values of "10: 2, 8: 1, 12: 5" and to have space and comma separate them like "10 2, 8 1, 12 5"
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()])
print(my_str)
1 2, 2 3, 3 4