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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -