Skip to main content
sanjuktab2257
Inspiring
May 2, 2025 3:08 PM UTC
Question

Is 2 operations within the same expression in a for each loop possible?

Can we perform 2 operations within the same expression of a forEach loop possible? (Ex: zip in python.)

7 replies

stefanhelzle0001
Brainy
May 2, 2025 3:19 PM UTC

Not sure what you are looking for. Do you want to describe the problem you want to solve?

Inspiring
May 2, 2025 3:33 PM UTC

You can perform many operations within the same expression of a forEach loop.  Anything in particular you're having difficulty doing?

yashwantha0914
Participating Frequently
May 2, 2025 5:12 PM UTC

Hi [mention:9ce4b939559d45dc807b9271b84c0a9b:e9ed411860ed4f2ba0265705b8793d05] 

"zip in python", so based on this i read about zip function in python

So, we have a similar function in Appian: merge()

A
nd can you please explain your usecase.

sanjuktab2257
Inspiring
May 5, 2025 11:15 PM UTC

Thank you [mention:f0523105fd4d4e879f169a28f3dd0ec5:e9ed411860ed4f2ba0265705b8793d05] , that was helpful.

It seems like "merge" is only for lists. Do you know how to merge two dictionaries.

a!localVariables(
  local!var1: {"John": "A", "Sam": "B", "Rose": "C"},
  local!var2: {"Smith": 1, "Williams": 2, "Thompson": 3},
  a!forEach(items: merge(local!var1.value, local!var2.value),
  expression: concat(fv!item[1], " ,", fv!item[2])
)

the expected output should be: "A ,1", "B, 2", "C, 3"

New Participant
May 6, 2025 2:30 AM UTC

hi [mention:9ce4b939559d45dc807b9271b84c0a9b:e9ed411860ed4f2ba0265705b8793d05] , see if this helps.

a!localVariables(
local!var1: { "John": "A", "Sam": "B", "Rose": "C" },
local!var2: { "Smith": 1, "Williams": 2, "Thompson": 3 },
local!var1Values: a!flatten(
a!forEach(
items: a!keys(local!var1),
expression: if(
fv!isLast,
stripwith(keyval(local!var1, fv!item, ":", ","), "]"),
keyval(local!var1, fv!item, ":", ",")
)
)
),
local!var2Values: a!flatten(
a!forEach(
items: a!keys(local!var2),
expression: if(
fv!isLast,
stripwith(keyval(local!var2, fv!item, ":", ","), "]"),
keyval(local!var2, fv!item, ":", ",")
)
)
),
merge(local!var1Values, local!var2Values)
)