Summary: Add helper for inserting a value after another value in an

OrderedDict (or Django's SortedDict)
 - Legacy-Id: 8719
This commit is contained in:
Ole Laursen 2014-11-30 14:47:17 +00:00
parent cebc979282
commit 8e4459ad59

13
ietf/utils/ordereddict.py Normal file
View file

@ -0,0 +1,13 @@
def insert_after_in_ordered_dict(dictionary, key, value, after):
# there's no insert in ordered dict so re-add entries after confirm_acronym instead
dictionary[key] = value
reorder = False
l = dictionary.items() # don't mutate the dict while looping
for k, v in l:
if reorder and k != key:
del dictionary[k]
dictionary[k] = v
if k == after:
reorder = True