Nested maps in Python 3 -


i want transform list list = [" , 1 ", " b , 2 "] nested list [["a","1"],["b","2"]].

the following works:

f1_a = map(lambda x :[t.strip() t in x.split(',',1)],list) 

but not work python 3 (it work python 2.7!):

f1_b = map(lambda x :map(lambda t:t.strip(),x.split(',',1)),list) 

why that?

is there more concise way f1_4 achieve want?

python 3's map returns map object, need convert list explicitly:

f1_b = list(map(lambda x: list(map(lambda t: t.strip(), x.split(',', 1))), lst)) 

though in cases should prefer list comprehensions map calls:

f1_a = [[t.strip() t in x.split(',', 1)] x in lst] 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -