Hi, is there a way to use a dictionary returned fr...
# ask-community
n
Hi, is there a way to use a dictionary returned from a task in the with Flow block? i read in some threads that it could be done using an intermediate task to unpack it, any examples for such task?
k
So I always told people to unpack it, but I was wrong. You actually can.
Copy code
@task()
def abc(x):
    return {"a": 1, "b": 2}

with Flow("test") as flow:
    a = abc(1)
    test = a["a"]

flow.run()
Copy code
@task()
def abc(x):
    return {"a": 1, "b": 2}

@task()
def bcd(x):
    return x

with Flow("test") as flow:
    a = abc(1)
    test = a["a"]
    bcd(a["b"])
    

flow.run()
The
[]
for a task calls the built-in Prefect
GetItem
task
n
@task
def a():
return {'list_key':['item1',item2']}
with Flow('test') as flow:
t = a()
li = t['list_key']
for item in li:
do_something(item1
)
will this work?
k
This I don't think so. You should use
.map()
instead to loop. And then you need to unpack this yep.