我正在使用Python 3.2.3 IDLE。我看到有些人使用reduce命令,但由於某種原因,我沒有它。就像代碼不會出現在紫色中一樣,它會將reduce當作變量來識別。如何將列表中的數字相乘(刪除重複項後)?
這裏是我的代碼部分:
numbers = [10, 11, 11]
numbertotal = (set(numbers))
#removes duplicates in my list, therefore, the list only contains [10, 11]
print ("The sum of the list is", (sum(numbertotal))) #sum is 21
print ("The product of the list is" #need help here, basically it should be 10 * 11 = 110
我基本上要乘以名單後,我刪除重複的numbertotal
。
很多信息及彼列表的產品:http://stackoverflow.com/questions/2104782/returning-the-product-of-a-list – Stuart