Python: create a function to modify a list by reference not value
- by Jonathan
Hey all-
I'm doing some performance-critical Python work and want to create a function that removes a few elements from a list if they meet certain criteria. I'd rather not create any copies of the list because it's filled with a lot of really large objects.
Functionality I want to implement:
def listCleanup(listOfElements):
i = 0
for element in listOfElements:
if(element.meetsCriteria()):
del(listOfElements[i])
i += 1
return listOfElements
myList = range(10000)
myList = listCleanup(listOfElements)
I'm not familiar with the low-level workings of Python. Is myList being passed by value or by reference?
How can I make this faster?
Is it possible to somehow extend the list class and implement listCleanup() within that?
myList = range(10000)
myList.listCleanup()
Thanks-
Jonathan