From df2b2469e185b37819a1cf4d2828800937d1f60e Mon Sep 17 00:00:00 2001 From: tmeissner Date: Wed, 27 Aug 2014 16:51:12 +0200 Subject: [PATCH] added internal method _remove_note() to remove note with given id from note list --- python_3_oop/chapter02/notebook.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/python_3_oop/chapter02/notebook.py b/python_3_oop/chapter02/notebook.py index 4837edd..02a26b9 100644 --- a/python_3_oop/chapter02/notebook.py +++ b/python_3_oop/chapter02/notebook.py @@ -65,6 +65,20 @@ class Notebook: return note return None + def _remove_note(self, id): + '''Remove note(s) with given id from note list''' + if self._find_note(id): + removed = [] + index = 0 + for note in self.notes: + if str(note.id) == str(id): + removed.append(self.notes.pop(index)) + else: + index += 1 + self._set_id() + return removed + return False + def _set_id(self): '''set global last_id to highest id found in notebook''' id = 1