How to use index to get the value from the result of map function by Python 3? -
i try this:
def test(x): return x**2 = map(test,[1,2,3])
if value this:
for in a: print(a)
i 1,4,9
, works perfectly.
but if this: a[0]
. error raised.
i know because result of map function map class:
type(map(test,[1,2,3])) == <class 'map'>
which not subsciptable.
so how can use index value of result of map function?
note: behavior specific python 3.
convert map
object list
object:
a = list(map(test,[1,2,3]))
then can use list indices access individual elements.
Comments
Post a Comment