I have the following dictionary baz
, which is created by zipping the lists foo
and bar
:
foo = ['Blue', 'Red', 'Green']
bar = [1, 2, 3]
baz = dict(zip(foo, bar))
baz
{'Blue': 1, 'Red': 2, 'Green': 3}
I'd like to be able to print a comma-separated list of keys and values. To do so, I'm using:
for k, v in baz.items():
print(f'{k} {v}, ', end='')
This works, but there is a trailing comma after the last dictionary value. What's the best way to remove that comma?
(I tried sep=','
but doing so removes the commas altogether)
Thanks!