添加元素可以說我有一個元組像下面:在一個元組
s = 15, 50, 71, 4, 19
,我試圖在元組逐一互相元素添加每個元素。即找到15和50,15和71等的總和...
所以我試圖搞砸地圖功能,但我從來沒有使用過它,但我已經拿出這個,但我得到TypeError:map()的參數2必須支持迭代錯誤。
test1 = tuple(map(operator.add, s[0], s[1]))
我也試圖讓每個元素的整數,但我也得到一個錯誤
test1 = tuple(map(operator.add, int(s[0]), int(s[1])))
我希望另一種方法有人知道我能做到什麼,我試圖做的。
謝謝!
編輯:
謝謝大家,所有的建議都是有益的,我發現了一些不同的方式做什麼,我需要做!
你期望的輸出成爲你的榜樣? – interjay
和你有沒有關心,如果有重複? –
爲了最終結果,可以說我正在尋找2的數字等於65的總和,所以我試圖找出哪兩個數字的組合將等於那個數字 – Neemaximo