【发布时间】:2023-02-15 08:40:28
【问题描述】:
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 object at 0x00000...> 和 <filter object at 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]
【问题讨论】:
-
map返回一个地图对象——如果您希望它是一个列表,请通过list()发送输出。 -
这回答了你的问题了吗? How to use filter, map, and reduce in Python 3
标签: python python-3.x