import sys
#Multiply the value in the list based on the selected value of s
def scale(l, s):
return map(lambda x: x * s, l)
#Sort the value based on the last digit value
def sort(l):
return sorted(l, key=lambda x: x % 10)
#Output number if is greater than average total
def goodSales(l):
return filter(lambda x: x > sum(l) / len(l), l)
seq = sys.argv[1]
sca = sys.argv[2]
seq = [int(x) for x in seq.split(',')]
sca = int(sca)
print('The scaled number is:', scale(seq, sca),
'The sorted sales numbers are:', sort(seq),
'The good sales numbers are:', goodSales(seq),)
因此,当我尝试运行这个程序时,我将面临这个问题,输出将显示〈Map对象在0x00000...〉和〈过滤器对象在0x00000...〉。我真的不知道哪里出错了,有人能给予一些建议吗?
输入
python sales.py 10,20,30,40,50,60 2
预期产出
The scaled number is: [20, 40, 60, 80, 100, 120] The sorted sales
numbers are: [10, 20, 30, 40, 50, 60] The good sales numbers are:
[40, 50, 60]
2条答案
按热度按时间oiopk7p51#
像这样改变你的功能,
map
返回Map对象和filter
返回过滤器对象,因此将它们转换为列表。dbf7pr2w2#
你可以使用列表解析,它更简洁,例如: