0

I have the following python program

ml = [x for x in range(1,4)]
f = lambda x : x*2

print(f(ml))

nl = map(f,ml)
print(nl)

The output is given below.

[1, 2, 3, 1, 2, 3]
<map object at 0x1005fada0>

map() is returning a map object is it possible to turn that into a list?

liv2hak
  • 14,472
  • 53
  • 157
  • 270

2 Answers2

1

Probably you are using python 3.x. Cast the map object to a list.

n1 = list(map(f,m1))

For a reference, read from here

Ahsanul Haque
  • 10,676
  • 4
  • 41
  • 57
1

Yes. Send it to list().

n1 = list(n1)
TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97