What's the best approach to using a for loop that ...
# ask-community
j
What's the best approach to using a for loop that would normally be within the
main
section of a standard python script?
k
Mapping would be the analog if the tasks are independent. If it’s a sequential loop, we have Task Looping
j
This seems a little on the side of what I was thinking of. Right now I have a couple functions, which are then used in a for loop at the bottom. E.g.
Copy code
for x in my dict:
        id= dict[x]
        response1= function1(id)
        file= function2(id, response1)
        result= functino3(id, file)
k
Yes that should be able to be done by mapping
j
does my dictionary go in the .map(1, 2, 3) in the example?
k
Use a task to either pull out the keys or values since you need to map over a List
j
if you were rewriting my example above then, there would be a task before the first row in the for loop, which gets at the keys, and then
I guess I'm trying to visualize this outside of the numerical example on the help page
k
Copy code
with Flow() as flow:
    ids = get_keys(dict)
    response1 = function1.map(ids)
    files = function2.map(ids, response1)
    result = function3.map(ids, files)
response1
,
files
,
result
being Lists
j
Mapping cannot be done over dictionaries?
k
Maybe it can, but I wouldn’t advise because it’s not explicit whether you’re mapping over keys or values