Created
October 4, 2016 12:56
Revisions
-
thomasvnl created this gist
Oct 4, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ def promote_item_to_first_position(enumerator, key, value): """ Promotes an item to the first index of the list if it isn't already there. It moves the item from it's current position and resets the list's indexes. Be careful to not use this on a giant list, because the operation could be quite heavy. With small lists the impact is not noticeable. :param enumerator: :param key: :param value: :return: """ for idx, item in enumerate(enumerator): if item[key] == value: if idx != 0: del enumerator[idx] enumerator.insert(0, item) break return enumerator