Dictionary Order Preserved in For In Loop?

183
0
11-09-2023 11:03 AM
Labels (1)
rlyding
New Contributor III

I was trying to find an answer searching the internet and wasn't able to find anything. In Arcade when iterating through a Dictionary in a For In loop are the dictionary values iterated in order like an Array would? I remember in older versions of Python this was an issue if you wanted to maintain a specific iteration order on a dictionary. Wanted to verify with Arcade if this was the case. In the example below I would like the For In loop to always go through the Dictionary in the order I have established 1 thru 7. It appears to be working, but I wanted to verify. I suppose to be safe I could use an Array to establish a ordered key.

//Set the feature search distance
var dist = 100
 
//Create a Dictionary of Priority and FeatureSetByName
var dict = Dictionary(1,"SewerLiftStation",2,"SewerManholeVault",3,"SewerFitting",4,"CleanoutDevice",5,"MeterDevice",6,"ServiceConnection",7,"SewerGravityMain")
 
//Loop to search for features starts by searching for Priority 1 features if no features are found proceed to Priority 2 etc...
for(var p in dict) {
  var lyr = dict[p]
  var fs = Intersects(FeatureSetByName($map, lyr, ['assetid'], false), Buffer($feature, dist, 'feet'))
  if(Count(fs) > 0) return First(fs).assetid
}
return "No Features Found Within" + " " + dist + " " + "Feet"
 
 
Thanks for any help with this.

 

Tags (3)
0 Kudos
0 Replies