Hi,
I have a dictionary that where I want to replace values in dictionary.
I created this dictionary with default values:
{“workingSchedule”:{“days”:“0,1,2,3,4”,“from”:“7:00”,“to”:“19:00”},“identifier”:{“displayName”:“x”,“roomNumber”:“y”}};
In the multiple dictionaries created by repetition, I want to replace the value of “x” and “y” per dictionary with the corresponding index of displayName and roomNumber.
I can’t figure out a way to do this. Please help.
Are you wanting to end up with completely separate dictionaries for separate displayName
, roomNumber
pairs or do you want one dictionary with sub-dictionaries for each pair and workingSchedule
?
Either way, I don’t think you’ll be able to “duplicate” directly, so you’ll have to recreate the dictionary each time. You can certainly do this with the out of the box nodes but python might be easier. With nodes, it might be easier to pull all your data apart (or start from scratch) and match up all the values. Then just build each dictionary with a unique name/id.
A function might work
def mltDct (x,y){
return {"workingSchedule":{"days":"0,1,2,3,4","from":"7:00","to":"19:00"},
"identifier":{"displayName":x,"roomNumber":y}};
};
5 Likes
Hello, I tried in python.
Python script:
import sys
for i,j,k in zip(range(len(IN[0])),IN[1],IN[2]):
IN[0][i]["identifier"].update({"roomNumber":k,"displayName":j})
OUT = IN[0]
Cordially
christian.stan
2 Likes
Thank you @Vikram_Subbaiah ! exactly what I wanted to achieve.
3 Likes