Skip to content

Instantly share code, notes, and snippets.

@Gee19
Created December 16, 2016 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gee19/c8491e96aa1ac5609cc59f6f3e6ac57f to your computer and use it in GitHub Desktop.
Save Gee19/c8491e96aa1ac5609cc59f6f3e6ac57f to your computer and use it in GitHub Desktop.
def insert_after(self, the_list, after, items_to_insert):
after_obj = next((i for i in the_list if
getattr(i, 'id', None) == after or getattr(i, 'name',
None) == after))
for item in reversed(items_to_insert):
try:
the_list.insert(the_list.index(after_obj) + 1, item)
except ValueError as exc:
raise IntegrationPluginException(
"Item doesn't exist in the list: {0}".format(exc.message))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment