使用戶進入他們想讀txt文件,文本文件通常包含如何使它所以只有鑰匙顯示dict-蟒蛇
a eats b
b eats c
c eats d
f_web = open(input('enter text wanted evaluated:'))
def web(enter text):
food_web = f_web
tuple_data = []
for line in food_web:
a = line.strip().split()
tuple_data.append((a[0].strip(), a[-1].strip()))
output = defaultdict(list)
for x, y in tuple_data:
output[x].append(y)
print ('Predators and Prey:')
for Predators, Prey in output.items():
values = ' , '.join(Prey)
print ('\t{} eats {}'.format(Predators, values))
return web
web(f_web)
我想我的程序來顯示當前的東西,事後顯示哪些掠食者只是掠食者而且從不吃東西。所以像這樣的
從來沒有吃過:
一個
打開(輸入...)可能會引發錯誤... –
我編輯它,但如何將ü建議我改變呢? – user3531022
在一行中調用輸入,並在另一個文件中打開輸入。 –