Skip to content

Commit 8e4459a

Browse files
committed
Summary: Add helper for inserting a value after another value in an
OrderedDict (or Django's SortedDict) - Legacy-Id: 8719
1 parent cebc979 commit 8e4459a

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

ietf/utils/ordereddict.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def insert_after_in_ordered_dict(dictionary, key, value, after):
2+
# there's no insert in ordered dict so re-add entries after confirm_acronym instead
3+
dictionary[key] = value
4+
5+
reorder = False
6+
l = dictionary.items() # don't mutate the dict while looping
7+
for k, v in l:
8+
if reorder and k != key:
9+
del dictionary[k]
10+
dictionary[k] = v
11+
12+
if k == after:
13+
reorder = True

0 commit comments

Comments
 (0)