0

I have an OrderedDict that starts with one value. and I want to add values while iterating the OD. this should be something like this:

od = OrderedDict(0:"")
for key, value in od.items():         # iterate over the values that are added 
    if value==target: return key
    key1 = foo1(key)
    if od.get(key1, None) is None: od[key1] = koo1(value)
    key2 = foo2(key)
    if od.get(key2, None) is None: od[key2] = koo2(value)

my intention is to implement a similar algo to BFS while building the "tree" and avoiding duplicates.

is OrderDict allow something like this?

  • `OrderedDict` is a subclass of `dict` so the usual rules about changing while iterating apply. See [Modifying a Python dict while iterating over it](https://stackoverflow.com/questions/6777485/modifying-a-python-dict-while-iterating-over-it). – sj95126 Oct 22 '22 at 14:09

0 Answers0