importdatetime# Store the next available id for all new noteslast_id=0classNote:'''Represent a note in the notebook. Match against a
string in searches and store tags for each note.'''def__init__(self,memo,tags=''):'''initialize a note with memo and optional
space-separated tags. Automatically set the note's
creation date and a unique id'''self.memo=memo
self.tags=tags
self.creation_date=datetime.date.today()globallast_id
last_id+=1self.id=last_iddefmatch(self,filter):'''Determine if this note matches the filter
text. Return True if it matches, False otherwise.
Search is case sensitive and matches both text and
tags.'''returnfilterinself.memoorfilterinself.tagsclassNotebook:'''Represent a collection of notes that can be tagged,
modified, and searched.'''def__init__(self):'''Initialize a notebook with an empty list.'''self.notes=[]defnew_note(self,memo,tags=''):'''Create a new note and add it to the list.'''self.notes.append(Note(memo,tags))def_find_note(self,note_id):'''Locate the note with the given id.'''fornoteinself.notes:ifstr(note.id)==str(note_id):returnnotereturnNonedefmodify_memo(self,note_id,memo):'''Find the note with the given id and change its
memo to the given value.'''note=self._find_note(note_id)ifnote:note.memo=memoreturnTruereturnFalsedefmodify_tags(self,note_id,tags):'''Find the note with the given id and change its
tags to the given value.'''note=self._find_note(note_id)ifnote:note.tags=tagsreturnTruereturnFalsedefsearch(self,filter):'''Find all notes that match the given filter
string.'''return[notefornoteinself.notesifnote.match(filter)]