Answer the question
In order to leave comments, you need to log in
Outputting a dictionary of lists without brackets, how to do it?
I have a final dictionary of lists:
{'Vika': [2, 0, 0, 2, 0], 'Danya': [2, 1, 0, 1, 3], 'Lisa': [2, 2, 0 , 0, 6]}
I need it to be output in the following format:
Vika:2 0 0 2 0
Danya:2 1 0 1 3
Lisa:2 2 0 0 6
Answer the question
In order to leave comments, you need to log in
d = {'Вика': [2, 0, 0, 2, 0], 'Даня': [2, 1, 0, 1, 3], 'Лиза': [2, 2, 0, 0, 6]}
for key, value in d.items():
print(key, ':', ' '.join(str(x) for x in value))
my_dict = {
'Вика': [2, 0, 0, 2, 0],
'Даня': [2, 1, 0, 1, 3],
'Лиза': [2, 2, 0, 0, 6]
}
for key in my_dict:
print(f"{key}: {str(my_dict[key]).replace('[', '').replace(']', '')}")
d = {'Вика': [2, 0, 0, 2, 0], 'Даня': [2, 1, 0, 1, 3], 'Лиза': [2, 2, 0, 0, 6]}
[print(i,':',*d[i]) for i in d]
I hope this makes it clearer how things work. Is each line clear?
d = {'Вика': [2, 0, 0, 2, 0],
'Даня': [2, 1, 0, 1, 3],
'Лиза': [2, 2, 0, 0, 6]}
for key, values in d.items():
string_values = [str(i) for i in values]
joined = ", ".join(string_values)
print(f"{key}: {joined}")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question