2011-12-05 92 views
3

我有一個非常具體的問題,我需要知道如何交換列表或元組中的元素。 我有一個名爲板狀的列表,我知道需要交換的元素。我如何交換它們?在具有二維數組的Java中,我可以輕鬆地執行標準交換技術,但在這裏它表示元組分配是不可能的。如何交換元組中的元素?

這裏是我的代碼:

board_state = [(0, 1, 2), (3, 4, 5), (6, 7, 8)] 

new = [1, 1] # [row, column] The '4' element here needs to be swapped with original 
original = [2, 1] # [row, column] The '7' element here needs to be swapped with new 

的結果應該是:

board_state = [(0, 1, 2), (3, 7, 5), (6, 4, 8)] 

我怎麼換?

回答