Python 在删除重复项后,如何将列表中的数字相乘?

Python 在删除重复项后,如何将列表中的数字相乘?,python,Python,我使用的是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",

我使用的是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
中的重复项后,将列表相乘。您的
reduce
隐藏在:

from functools import reduce

print("The product of the list is", reduce(lambda x,y:x*y, numbertotal))


在python3中,它已移动到
functools

这对你有用吗

product = 1
for j in numbertotal:
    product = product * j
print 'The product of the list is', product

哦,好的。我想我已经运行了这个命令,但它与我的代码不兼容:(这里有很多关于获取列表产品的信息:
product = 1
for j in numbertotal:
    product = product * j
print 'The product of the list is', product