如何打印没有任何特殊字符的词典


myDict = {"word" : [10],
"other word" : [16]}

我想知道我如何才能以这种格式打印出来:

word 10
other word 16

遍历dict中的键/值对并逐行打印它们在大多数情况下是一个坚实的起点:

for key, value in myDict.items():
print(key, *value, sep = " ")

您需要使用*或析构函数运算符,因为您的值是list

为了更深入地研究几个例子,以下是文档中的一个很好的例子:https://docs.python.org/3/tutorial/datastructures.html#looping-技术

相关内容

最新更新