Python 3's map returns a map object, which you need to convert to list explicitly:

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

Though in most cases you should prefer list comprehensions to map calls:

f1_a = [[t.strip() for t in x.split(',', 1)] for x in lst]
Answer from vaultah on Stack Overflow
๐ŸŒ
Learning Python
learning-python.com โ€บ map-nesting-example.py
File: map-nesting-example.py
#----------------------------------------------------------------------- x = [0, 1, 2] y = [100, 200, 300] fn = lambda x: lambda y: x + y n = [] list( map( lambda x: n.extend(map(x, y)), map(fn, x) ) ) print(n) #----------------------------------------------------------------------- # 3) original, with operations decomposed for clarity #----------------------------------------------------------------------- X = [0, 1, 2] Y = [100, 200, 300] def fn(x): def fm(y): return x + y # a closure: remembers "x", expects "y" return fm temp = map(fn, X) # functions, each with a saved "x" value n = [] for
Discussions

python 3.x - Operating on Nested Tuples using Map function - Stack Overflow
Communities for your favorite technologies. Explore all Collectives ยท Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
๐ŸŒ stackoverflow.com
July 18, 2019
"Map" a nested list in Python - Stack Overflow
For large nested lists on CPython ... the nested list comprehensions is usually going to be the fastest. ... Sign up to request clarification or add additional context in comments. ... The first argument requires a function, and as such, you can utilize the lambda operator to map float to the ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
The map() function or the list comprehension?
There are two ways to apply a function to each element of an iterated object in python: the map function: >>> lst = [1, 2, 3, 4] >>> list(map(str, lst)) ['1', '2', '3', '4'] >>> list(map(lambda a: a + 1, lst)) [2, 3, 4, 5] the list comprehension: >>> lst = [1, 2, 3, 4] >>> [str(i) for i in ... More on discuss.python.org
๐ŸŒ discuss.python.org
5
1
September 12, 2023
python - How to make map for a nested function? - Stack Overflow
My intention was to mutate the list without using return. So my apporach was to create a helperfunction to modify the value and then map it to the whole list. However, map only consumes one functio... More on stackoverflow.com
๐ŸŒ stackoverflow.com
June 11, 2019
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ using list(map()) on a nested dict
r/learnpython on Reddit: Using list(map()) on a nested dict
May 15, 2018 -

So I have a list of characters. And let's say I need to get at each of the characters class types. Using map() in python 3, how exactly would one go about this? Here's the list of characters. I've tried going at this a few ways, but they have all failed. The real issue is that I'm not sure how to get at the nested dictionary.

chars = [{'Character1': {'age': 19, 'name': 'Balthazar', 
    'class': 'Wizard'}}, {'Character2': {'age': 24, 
    'name': 'Thadeus', 'class': 'Warrior'}}]

classes = list(map(lambda x: x.update({"classes": 
    list(map(lambda y: # need to get at each 'class' key 
    here to output to the list of classes), collection)}), 
    chars))

EDIT: This is something I'm working on at work. I'm a Jr. Dev, and these made up dictionaries hold no value to what I'm actually working on whatsoever. I just need to understand how this works and am not coming up with much in my searching.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-a-nested-for-loop-to-a-map-equivalent-in-python
Convert a nested for loop to a map equivalent in Python - GeeksforGeeks
December 27, 2021 - Map function simply applies the specified function on the given iterable and returns the modified iterable as the result. ... # create two sample lists lst1 and lst2 as shown lst1 = [10, 20, 30] lst2 = [3, 4, 5] # this empty list stores the ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ convert-a-nested-for-loop-to-a-map-equivalent-in-python
Convert a nested for loop to a map equivalent in Python
May 30, 2023 - Nested for loops execute repetitive ... the outer loop. Python's map() function provides a functional programming approach to achieve similar results by applying functions to iterables....
๐ŸŒ
geekflare
geekflaread.pages.dev โ€บ posts โ€บ python map function explained with examples
Python Map Function Explained With Examples | geekflare
December 20, 2022 - You can also use nested map() functions, where the inner map function is used to compute the square root list nums_sqrt, and the outer map function performs the rounding operation.
๐ŸŒ
denofgeek
denofgeekac.pages.dev โ€บ posts โ€บ python map function explained with examples
Python Map Function Explained With Examples | denofgeek
November 16, 2022 - You can also use nested map() functions, where the inner map function is used to compute the square root list nums_sqrt, and the outer map function performs the rounding operation.
Find elsewhere
๐ŸŒ
Medium
oluwateezzy03.medium.com โ€บ python-nested-dictionaries-common-pitfalls-and-better-error-handling-8a31d4724cbb
Python Nested Dictionaries, Common Pitfalls, and Better Error Handling | by Oluwatobiloba Olamide | Medium
June 19, 2025 - Working with nested dictionaries (or nested maps) in Python is a common pattern, especially when dealing with JSON data, configuration files, or APIs. A frequent task is to safely traverse a nested structure using a sequence of keys. But what happens when something goes wrong โ€” and are we raising the right exceptions? In this post, Iโ€™ll walk you through a utility function called access_nested_map, the original design, a key observation I made, and how to improve it for clarity and correctness.
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-41022.html
Help with nested maps
def parse_map(self, data, map_name): lines = data.strip().split('\n') result = {} map_stack = [] for line in lines: line = line.strip() if line == '---': if map_stack: current_map = map_stack.pop() if
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 57090754 โ€บ operating-on-nested-tuples-using-map-function
python 3.x - Operating on Nested Tuples using Map function - Stack Overflow
July 18, 2019 - rect = [(2,4),(3,5),(4,3),(5,5),(6,2),(3,9)] areas=[] def area(r): for i in rect: a = i[0] b = i[1] c = a*b areas.append(c) ...
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
The map() function or the list comprehension? - Python Help - Discussions on Python.org
September 12, 2023 - There are two ways to apply a function to each element of an iterated object in python: the map function: >>> lst = [1, 2, 3, 4] >>> list(map(str, lst)) ['1', '2', '3', '4'] >>> list(map(lambda a: a + 1, lst)) [2, 3,โ€ฆ
Top answer
1 of 1
1

TL;DR: With current Python typing support, this is probably just impossible. Sorry.

First of all, you definitely can't write a type hint that preserves the exact structure of the input. That would rely on structure-preserving type hints for flat lists, which don't exist (and would run counter to the purpose of a list if they did).

That means the best you can hope for is an annotation that preserves union types for each nesting level. This is already suboptimal because if one level contains, say, both lists and tuples, every element in that level would have a type of list | tuple, which discards information. The type mappings would look something like this:

list[A | list[A | list[A]]] -> list[B | list[B | list[B]]]
list[A | tuple[A, A | list[A]] -> list[B | tuple[B, B | list[B]] 

Unfortunately, even this probably isn't doable. In order for this to work, you'd need to use nested generics like your "parameterize one variable by another" attempt, which I'll reproduce here:

def nested_mapA, B, C: NestedStructure -> C[B]: ...

Nested generics like C[A] are "higher-kinded types", which just don't exist in Python. There is an open feature request on GitHub that's still seeing some activity, but it hasn't even been formulated into a PEP yet.

I don't think there's a way to do this without higher-kinded types:

  1. The original leaf type needs a TypeVar since it defines an abstract relationship between the callback and parameter types.
  2. The new leaf type needs a TypeVar since it defines an abstract relationship between the callback and return types.
  3. The structure of the nested iterable needs a TypeVar since it defines an abstract relationship between the parameter and return types.
  4. These three TypeVars must be separate because none can be inferred from the others.
  5. It must be possible to narrow one abstract type (the iterable) based on another abstract type (the leaves).

The final requirement in particular basically forces you to use nested generics.

๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ multiprocessing map with nested functions
r/learnpython on Reddit: multiprocessing map with nested functions
October 29, 2015 -

I am trying to use multiprocessing to speed up some processes in my code but I want it to be optional and I was as few changes as possible for the parallel version.

As such, I am trying to write everything as functions with the only difference being whether you use Python's map or multiprocessing.Pool.map()

This requires some use of nested functions but I keep getting the following error:

PicklingError: Can't pickle <type 'function'>:attribute lookup __builtin__.function failed

I think it has to do with nested functions. To try to demonstrate, I made the following working example:

import multiprocessing as mp

## Works

def fooA(q):
    return q**2

pool = mp.Pool()
ResA_S = map(fooA,range(10))
ResA_P = pool.map(fooA,range(10))
pool.close()
assert ResA_S==ResA_P

## Fails

def bar():
    def fooB(q):
        return q**2
    pool = mp.Pool()
    ResB_S = map(fooB,range(10))
    ResB_P = pool.map(fooB,range(10))
    pool.close()
    return ResB_S,ResB_P

ResB_S,ResB_P = bar()
assert ResB_S==ResB_P

Any ideas on how I can fix this? Or work around it? I really want to have something like the following:

if doPar:
    pool = mp.Pool()
    res = pool.map(func,inputs)
    pool.close()
else:
    res = map(func,inputs)

so that everything else remains the same.

Thoughts? Ideas?

Thanks!

๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 50711353 โ€บ nested-map-function-of-functools-subpress-one-line
python - nested map function of functools subpress one line - Stack Overflow
I wonder that is there any fancy way for nested map function. ... import functools y1 = [1,2] y2 = [3,4] y3 = [5,6] alldata = [y1,y2,y3] result = map(lambda f : map(lambda s : s*10 , f) , alldata) ... A list comprehension may be more readable, but I think your current code is about as good as it gets. ... You current code is good, but if you consider Python's syntax for anonymous functions a bit heavy, you could use a list-comprehension or, if you want to preserve map's laziness, a generator comprehension.