Created
November 28, 2023 15:57
-
-
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
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 characters
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