from song import Song # An Album is a collection of songs class Album: """An album is a collection of songs. The Album class defines a number of overloaded operators""" def __init__(self, s_ist): """Constructor""" self.songs = [] for s in s_ist: self.songs += [s] def __str__(self): """Sting representation""" ret_str = '++++++++\n' for i in range(len(self.songs)): ret_str += str(i+1) + ':' + str(self.songs[i]) ret_str += '\n++++++++\n' return ret_str def __len__(self): """Overload the len() function """ return len(self.songs) def __add__(self, new_song): """Overaload the + operator""" self.songs += [new_song] return self def __iadd__(self, new_song): """Overload the += operator""" self.songs += [new_song] return self def __contains__(self, a_song): """Overload the in operator""" return a_song in self.songs