![](/img/trans.png)
[英]When creating a dictionary from a textfile, how do i add a newline to the dictionary?
[英]How do I add newline to only dictionary values?
import pprint
def print_values(key):
pprint.pprint(key, width=1)
我試過了,但最終同時打印了鍵和值。 我只想讓設備打印值,而不是鍵。
最好的方法是...
import pprint
def print_values(key):
pprint.pprint(dictionary[key], width=1)
要僅打印字典的鍵/值,請執行以下操作:
dictionary = {'abc': 123, 'def': 456, 'ghi': 789}
# print the keys
for entry in dictionary:
print(entry)
# print the values
for entry in dictionary:
print(dictionary[entry])
# print the values
for entry in dictionary.values():
print(entry)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.