I have a bunch of Album
objects in a list
(code for objects posted below). 5570 to be exact. However, when looking at unique objects, I should have 385. Because of the way that the objects are created (I don't know if I can explain it properly), I thought it would be best to add all the objects into the list, and then delete the ones that are similar afterwards.
Certain objects have the same strings for each argument(artist
, title
, tracks
) and I would like to get rid of them. However, I know I cannot simply remove the duplicates, since they are stored in separate memory locations, and therefore aren't exactly identical.
Can anyone help me with removing the duplicates?
As you can probably tell, I am quite new to python.
Thanks in advance!
class Album(object) :
def __init__(self, artist, title, tracks = None) :
tracks = []
self.artist = artist
self.title = title
self.tracks = tracks
def add_track(self, track) :
self.track = track
(self.tracks).append(track)
print "The track %s was added." % (track)
def __str__(self) :
return "Artist: %s, Album: %s [" % (self.artist, self.title) + str(len(self.tracks)) + " Tracks]"