Home > OS >  dictionary format without brackets and comma
dictionary format without brackets and comma

Time:04-19

I have the dict:

{'Спартак': [2, 0, 1, 1, 1], 'Зенит': [2, 0, 1, 1, 1], 'Локомотив': [2, 2, 0, 0, 6]}

i need print format like:

Спартак:2 0 1 1 1

i try this:

for key, value in commands_dict.items():
print("{0}:{1}".format(key, value))

and this return screen, but that's not what I need

thank you for you answer!

CodePudding user response:

try:

for key, value in commands_dict.items():
    print("{0}:{1}".format(key, ",".join(map(str,value))))

Note:

  • map converts each integer to string
  • join concatenates the strings with comma as the delimiter
  • Related