0
我在想:如何從函數中的字典中單獨打印鍵或值?Python:單獨打印字典鍵和值
例.txt文件
00000000;Pikachu Muchacho;region1
11111111;SoSo good;region2
22222222;Marshaw williams;region3
33333333;larry Mikal Carter;region3
代碼
test_file = open("test.txt", "r")
customer = {}
def dictionary():
for line in test_file:
entries = line.split(";")
key = entries[0]
values = entries[1]
customer[key] = values
def test():
print(customer)
print(customer[key])
def main():
dictionary()
test()
main()
customer.keys()和customer.values()給你所有的鍵和所有的值 – jamesRH
我不是downvoting,但這是我真誠的建議,你在提出這樣的問題之前做更多的努力。 – Pukki
我確實付出了努力。這就是爲什麼我問,因爲我嘗試了幾種不同的方法,我沒有弄明白。在給你的意見之前給它一點想法。我對語言和編碼一般都不熟悉。 –