You can subclass list
to print when changing the list.
Here's an example:
class EventList(list):
def __setitem__(self, key, value):
super(EventList, self).__setitem__(key, value)
print("The list has been changed!")
def __delitem__(self, value):
super(EventList, self).__delitem__(value)
print("The list has been changed!")
def __add__(self, value):
super(EventList, self).__add__(value)
print("The list has been changed!")
def __iadd__(self, value):
super(EventList, self).__iadd__(value)
print("The list has been changed!")
def append(self, value):
super(EventList, self).append(value)
print("The list has been changed!")
def remove(self, value):
super(EventList, self).remove(value)
l = EventList(["apples","bananas"])
l.append('test')
Prints:
The list has been changed!
OR
Just compare lists:
old_list = ["apples","bananas"]
new_list = ["apples","bananas"]
newer_list = ["apples","bananas", "oranges"]
old_list == new_list #true
old_list == newer_list #false
This would work with no subclass as ==
compares if the lists have the same elements in the same indicies not if they are exactly the same by id or hash (in lamens). Just save the old one in a variable, then when you want to check just use this. (note: this does not provide a way for the print to be automatically called. It's just another way)