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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -