I have an issue with clearing lists. In the current program, I have a method that clears a certain number of lists. This is rather inconvenient since during one part of the program where this method is used, it would be a lot more helpful if it only deleted the last element from the lists. Is there any way in which I can set index numbers as parameters to my method to solve this problem?
list
The code for the method
def clearLists(self): del self.Ans[:] del self.masses[:]
Whenever I want to use this method, I merely write self.ClearLists() and it deletes every element in a list.
self.ClearLists()
you can use lst.pop() or del lst[-1]
lst.pop()
del lst[-1]
pop() removes and returns the item, in case you don't want have a return use del
pop()
del
1.4m articles
1.4m replys
5 comments
56.9k users