[問題] 出現unhashable type: 'list'該如何處理

作者: qzxwec789 (Frank)   2019-03-22 03:58:05
大家好,我的code如下
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 21 23:47:43 2019
@author: user
"""
import random
Dict={"紅":"紅色","成":"成功","失":"失敗","漂":"漂亮","勇":"勇敢",
"天":"天空","寫":"寫字","力":"力量","走":"走路","手":"手機"}
TwoWords=list(Dict.keys())
print("\n")
correct = 0
incorrect = 0
while TwoWords:
InitialWord = random.choice(TwoWords)
TwoWords.remove(InitialWord)
print(InitialWord)
term=input ("請輸入詞彙:")
if term==Dict[TwoWords]:
print("答對了!\n")
correct+=1
else:
print("答錯了,應該是%s...\n"%Dict[TwoWords])
incorrect+=1
print('你答對%i題,答錯%i題!' %(correct, incorrect))
當出現如天,而同時出現請輸入詞彙:,這時不管我輸入甚麼字都出現錯誤訊息
如TypeError: unhashable type: 'list',所以想請教我的code應該要如何修改才行。
作者: ckc1ark (偽物)   2019-03-22 06:39:00
邏輯應該是Dict[InitialWord]
作者: as30385438 (LCT)   2019-03-22 11:18:00
現在不就只有10題嗎

Links booklink

Contact Us: admin [ a t ] ucptt.com