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
  • 13,641
  • 48
  • 139
  • 250

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
  • 9,865
  • 4
  • 35
  • 51
1

Yes. Send it to list().

n1 = list(n1)
TigerhawkT3
  • 46,954
  • 6
  • 53
  • 87