Good evening, some trouble with the below example code. This is my first time putting a loop in a function for Calculate Field. I've tried a number of ways (putting brackets after row in the condition of the for loop, putting a 0 inside the brackets, changing the equals sign, trying the brackets with Key, etc).
KeyList = ['a','b','c']
ValueList = ['chair','lamp','rug']
Dict = dict(zip(KeyList,ValueList))
codeblock = """
def output(Key,Value):
for row in KeyList:
if row == Key:
return Dict[KeyList]
else:
return Value"""
TableExample:
ID | NAME | (NewField) |
a | (chair) | |
z | desk | (desk) |
c | (rug) |
arcpy.management.CalculateField(
in_table = "TableExample",
field = "NewField",
expression = "output(!ID!,!NAME!)",
expression_type = "PYTHON3",
code_block = codeblock
)
Solved! Go to Solution.
my line 6...