Oct-08-2021, 01:53 AM
i want to delete select items from a list, such as those which have a specific value in a dictionary. this often gets pretty ugly. maybe i want to remove any string that is all digits. the problem i typically run into is when i need to delete items from an existing list instead of just rebuilding a new one. i need to use indexes and when an item is deleted the items with higher indexes change to one lower. then i need another loop to recheck the new item at the same index. it makes for some ugly code.
different use cases also need different tests to decide if the item needs to be removed, making it tough to make a common function. does anyone know of something in Python that can make this easier or more elegant?
i don't want to show code because any example would need to have specific parts, like the different cases for which items to delete, and answers may focus on that.
different use cases also need different tests to decide if the item needs to be removed, making it tough to make a common function. does anyone know of something in Python that can make this easier or more elegant?
i don't want to show code because any example would need to have specific parts, like the different cases for which items to delete, and answers may focus on that.