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, ...
Discussions

Using list(map()) on a nested dict
Fun! First off, pytoolz looks like it has some things that could help here. Second, this whole nested dictionary of dictionary bit makes it a lot harder. So here is what I came up with: >>> from itertools import chain >>> from operator import itemgetter >>> vg = lambda d:d.values() >>> cg = itemgetter('class') >>> list(map(cg,chain(*map(vg, c)))) ['Wizard', 'Warrior'] Where c = chars you have. I also wonder if itertools.starmap might make this less convoluted, but i've not used that much. If you find yourself doing these things, probably want to reconsider your choices in life, or at least look into pytoolz. More on reddit.com
๐ŸŒ r/learnpython
23
8
May 15, 2018
"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 sub-lists. This is an example... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Type-hinting a structure-preserving nested map in Python - Stack Overflow
I'm writing a Python function inspired by map that takes a function f: Callable[[A], B] and an arbitrarily nested structure of iterables (e.g. lists of tuples of lists of ... of objects of type A) ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
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
๐ŸŒ
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 - The reason is that the map object doesn't like to store the whole size of the iterable in its memory. So, to access the output, we would require to explicitly specify the output format of this map function to be a list. Example: Convert a nested for loop to a map equivalent
๐ŸŒ
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.

๐ŸŒ
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 code blocks, where an inner loop runs completely for each iteration of the outer loop. Python's map() function provides a functional programming approach to achieve similar results by applying functions to iterables.
๐ŸŒ
geekflare
geekflare.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.
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-41022-page-2.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: ...
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.

๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ map-and-filter-python
Python's map and filter functions - Python Morsels
August 3, 2026 - Sign in to your Python Morsels account to save your screencast settings. Don't have an account yet? Sign up here. Let's talk about the map and filter functions in Python, the differences between them, and why I don't usually recommend using them (related: I also don't recommend lambda expressions).
๐ŸŒ
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
... 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.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-use-the-python-map-function
Ultimate Guide to Python Map Function for Data Processing | DigitalOcean
Master Pythonโ€™s map() function with easy examples! Learn its syntax, lambda functions, user-defined functions, and using multiple iterables to optimize functโ€ฆ
๐ŸŒ
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!

๐ŸŒ
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.