Skip to content
Snippets Groups Projects
Commit 95b429a1 authored by nilsl99's avatar nilsl99
Browse files

Fixed Stack.__str__

parent 05780632
No related branches found
No related tags found
No related merge requests found
...@@ -4,11 +4,13 @@ class Stack(): ...@@ -4,11 +4,13 @@ class Stack():
self.stack = l self.stack = l
def __str__(self): def __str__(self):
max_length = len(str(max(self.stack, key=lambda x: len(str(x)))))
result = "" result = ""
vert = "\u2502" max_length = 1
for ele in reversed(self.stack): if not self.isEmpty():
result += vert + str(ele).rjust(max_length) + vert + "\n" max_length = len(str(max(self.stack, key=lambda x: len(str(x)))))
vert = "\u2502"
for ele in reversed(self.stack):
result += vert + str(ele).rjust(max_length) + vert + "\n"
return result + "\u2514" + "\u2500"*max_length + "\u2518" return result + "\u2514" + "\u2500"*max_length + "\u2518"
def push(self, element): def push(self, element):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment