Deletion of multiple items from a list or an array is always tricky because, while deleting multiple items the indices are updated automatically. One solution is to start deleting at the highest index so that the indices to be deleted later are always unaffected.
Here is the function I wrote for the extended textScrollList class. Python's built-in function to sort a list comes in handy here.
def removeAt(self, inds): """ Remove item(s) at given indices from textScrollList @inds: takes a single int or a list of int """ if not isinstance(inds,list): inds = [inds] # indices should be sorted first into descending order # so that the indices to be deleted next are unaffected inds.sort(reverse=True) for i in inds: self.edit(removeIndexedItem=i)
the right way to say "if type(inds) is not list:" is "if not isinstance(inds,list):".
ReplyDeleteAh I see! I will change it. Actually I will have to make this change in many places :)
ReplyDeleteThanks!