dictionary = {"00":[1,2,3,4,5,6,7,8,9],"01":[1,2,3,4,5,6,7,8,9],"02":[1,2,3,4,5,6,7,8,9],"03":[1,2,3,4,5,6,7,8,9],"04":[1,2,3,4,5,6,7,8,9]........up-to "99":[1,2,3,4,5,6,7,8,9]}
我必須從「00」列表中刪除值2。我試着用下面的語句。
del (dictionary[key][dictionary[key].index(sudokumatrix[i][iindex])]).
這裏的關鍵有值 「00」 和sudokumatrix [I] [iindex]具有價值2.But我得到了導致字典作爲
{"00":[1,3,4,5,6,7,8,9],"01":[1,3,4,5,6,7,8,9],"02":[1,3,4,5,6,7,8,9],"03":[1,3,4,5,6,7,8,9],"04":[1,3,4,5,6,7,8,9].....}.
我一定要得到的結果爲:
{"00":[1,3,4,5,6,7,8,9],"01":[1,2,3,4,5,6,7,8,9],"02":[1,2,3,4,5,6,7,8,9],"03":[1,2,3,4,5,6,7,8,9],"04":[1,2,3,4,5,6,7,8,9]....}
我在這裏張貼整個代碼:
dictionary = dict()
zerotonine = "123456789"
list2 = list(zerotonine)
list2 = [int(i) for i in list2]
sudokumatrix=[]
for p in range(9):
for q in range(9):
keyis=str(p)+str(q)
dictionary[keyis] = list2
for i in range(9):
initialinput = [1,2,3,4,5,6,7,8,9]
list1=list(initialinput)
list1 = [int(i) for i in list1]
sudokumatrix.append(list1)
key = "00"
del dictionary[key][dictionary[key].index(sudokumatrix[0][1])]
print dictionary
看看[簡單的方法來通過值刪除列表元素](https://stackoverflow.com/questions/2793324/is-there-a-simple-way-to-delete-a-list-element-by-value- in-python) – JGreenwell
無法用Python進行復制2.7.6 –
您應該發佈您的整個代碼。乍一看,這看起來像實習,它不是Python數組的默認行爲。從所有陣列沒有interning。 –