i am encountering this problem in F# [not C# where there is already a similar post with a similar answer]
I understand its not possible to modify a Dictionary while enumerating it in a for loop how should i go around that ?
let edgelist1 = [(1,2,3.0f);(1,2,4.0f);(5,6,7.0f);(5,6,8.0f)]
let dict_edges = new Dictionary<int*int,(int*int*float32) list>()
for x in edgelist1 do dict_edges.Add ((fun (a,b,c)-> (a,b)) x, x)
for k in dict_edges.Keys do dict_edges.[k] <- (dict_edges.[k] |> List.rev)
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.KeyCollection.Enumerator.MoveNext() at .$FSI_0101.main@()
individually this is working
dict_edges.[(1,2)] <- dict_edges.[(1,2)] |> List.rev;;
in the for loop i need just to change dictionary values, not keys.
thanks