From 12b58ccf9bc5593d6dbd30f5fc3dfa7ad1ab2f67 Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Sat, 29 Oct 2016 09:10:32 -0400 Subject: [PATCH] Update set of stacks challenge solution (#110) Add is_empty() method, remove extra linebreak. --- stacks_queues/set_of_stacks/set_of_stacks_solution.ipynb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/stacks_queues/set_of_stacks/set_of_stacks_solution.ipynb b/stacks_queues/set_of_stacks/set_of_stacks_solution.ipynb index f476670..e65df05 100644 --- a/stacks_queues/set_of_stacks/set_of_stacks_solution.ipynb +++ b/stacks_queues/set_of_stacks/set_of_stacks_solution.ipynb @@ -136,6 +136,9 @@ " def is_full(self):\n", " return self.num_items == self.capacity\n", "\n", + " def is_empty(self):\n", + " return self.num_items == 0\n", + "\n", "\n", "class SetOfStacks(object):\n", "\n", @@ -154,10 +157,9 @@ " if self.last_stack is None:\n", " return None\n", " data = self.last_stack.pop()\n", - " if not self.last_stack.num_items:\n", + " if self.last_stack.is_empty():\n", " self.stacks.pop()\n", - " self.last_stack = self.stacks[-1] \\\n", - " if len(self.stacks) else None\n", + " self.last_stack = self.stacks[-1] if self.stacks else None\n", " return data" ] },