Skip to content

How to map over a list of inputs and map over the results? #3287

Answered by jcrist
gryBox asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry, I'm left guessing at what you actually want here. Here's another attempt:

from prefect import Flow, task, apply_map, Parameter, unmapped, flatten
import random


@task
def list_maker(input_num):
    return [(random.randint(1, 10), input_num) for i in range(input_num)]


@task
def expensive_func(input):
    num_from_random_lst, num_from_input = input
    return num_from_random_lst * num_from_input


with Flow("map the map") as flow:
    input_num_lst = Parameter("input_num_lst", default=[2, 3])

    random_list = list_maker.map(input_num_lst)
    output = expensive_func.map(flatten(random_list))

state = flow.run()
print(state.result[output].result)
$ python test.py
[2020-09-10 17:4…

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@gryBox
Comment options

@jcrist
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by gryBox
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants