-1
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),)

So when I'm trying to run this program I will be facing this issue where the output will show <map object at 0x00000...> and <filter object at 0x00000....>. I'm not really sure what went wrong could anyone give some advice.

Input

python sales.py 10,20,30,40,50,60 2

Expected output

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]
theslasher
  • 21
  • 5
  • 1
    `map` returns a map object -- send the output through `list()` if you want it to be a list. – John Coleman Oct 10 '22 at 10:33
  • Does this answer your question? [How to use filter, map, and reduce in Python 3](https://stackoverflow.com/questions/13638898/how-to-use-filter-map-and-reduce-in-python-3) – Gino Mempin Oct 10 '22 at 11:40
  • Does this answer your question? [Why map and filter functions return iterator in python3?](https://stackoverflow.com/q/51695133/2745495) – Gino Mempin Oct 10 '22 at 11:41

2 Answers2

1

Change your functions like this,

#Multiply the value in the list based on the selected value of s
def scale(l, s):
    return list(map(lambda x: x * s, l))

#Output number if is greater than average total
def goodSales(l):
    return list(filter(lambda x: x > sum(l) / len(l), l))

map return map object and filter return filter object so convert those into a list.

Rahul K P
  • 15,740
  • 4
  • 35
  • 52
1

You can use List Comprehensions, it's cleaner, for example :

items = [
    ("name", 13),
    ("age", 12)

]

prices = [item[1] for item in items]
print(prices)

اوسكو
  • 27
  • 3