map with function for each element?

fra*_*ans 4 python functional-programming variable-assignment python-3.x iterable-unpacking

Very often I process single elements of tuples like this:

size, duration, name = some_external_function()
size = int(size)
duration = float(duration)
name = name.strip().lower()
Run Code Online (Sandbox Code Playgroud)

If some_external_function would return some equally typed tuple I could use map in order to have a (more functional) closed expression:

size, duration, name = map(magic, some_external_function())
Run Code Online (Sandbox Code Playgroud)

Is there something like an element wise map? Something I could run like this:

size, duration, name = map2((int, float, strip), some_external_function())
Run Code Online (Sandbox Code Playgroud)

Update: I know I can use comprehension together with zip, e.g.

size, duration, name = [f(v) for f, v in zip(
   (int, float, str.strip), some_external_function())]
Run Code Online (Sandbox Code Playgroud)

-- I'm looking for a 'pythonic' (best: built-in) solution!

To the Python developers:

What about

(size)int, (duration)float, (name)str.strip = some_external_function()
Run Code Online (Sandbox Code Playgroud)

? If I see this in any upcoming Python version, I'll send you a beer :)

bru*_*ers 5

很简单:使用函数和参数解包......

def transform(size, duration, name):
    return int(size), float(duration), name.strip().lower()

# if you don't know what the `*` does then follow the link above...    
size, name, duration = transform(*some_external_function())
Run Code Online (Sandbox Code Playgroud)

非常简单,完全可读和可测试。