Skip to content

Instantly share code, notes, and snippets.

@vhsu
Created November 28, 2023 15:57
Show Gist options
  • Save vhsu/0f1f2cd0126faa9a23f809713cc1fbef to your computer and use it in GitHub Desktop.
Save vhsu/0f1f2cd0126faa9a23f809713cc1fbef to your computer and use it in GitHub Desktop.
Take elements out of a list in python and get its value by index
def take_out_elements(list_object, indices):
"""Removes elements from list in specified indices"""
removed_elements = []
indices = sorted(indices, reverse=True)
for idx in indices:
if idx < len(list_object):
removed_elements.append(list_object.pop(idx))
return removed_elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment