-2
當我運行下面的代碼時,出現「需要多個值才能解包」的錯誤。誰能告訴我如何通過這本詞典迭代,以運行下面的代碼以列表的形式迭代字典,值爲
globalViewDict = {'A': [('B', 6.5, 5001), ('F', 2.2, 5005), 'A', '2'],
'B': [('A', 6.5, 5000), ('C', 1.1, 5002), ('D', 4.2, 5003), ('E', 3.2, 5004), 'B', '4']}
def dijkstrawPhase():
global globalViewDict
tempList =[]
temptup =()
i=0
x=0
value = []
for key,value in globalViewDict:
neighborsOfPacket = int(value[-1])
while x < neighborsOfPacket:
id = str(value[i+0])
cost = float(value[i+2:i+5])
temptup =(key,id,cost)
i = i + 11
x = x + 1
tempList.append(temptup)
print "tempList",tempList
dijkstrawPhase()
OP正在使用Python 2,我會添加一個關於'items'和'iteritems'的評論。 –
yup!謝謝! :D和新年快樂 –
@FranciscoCouzo:對,這幾天我默認爲Python 3,謝謝指出。 –