Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 21, Challenge 2 #9

Closed
jonathan-j-stone opened this issue Jun 8, 2017 · 1 comment
Closed

Chapter 21, Challenge 2 #9

jonathan-j-stone opened this issue Jun 8, 2017 · 1 comment

Comments

@jonathan-j-stone
Copy link

Your code at http://tinyurl.com/jj7d7nx2 for Challenge 2 in Chapter 21 returns:

[1, 2, 3, 4, 5,]

The challenge was to "create a new list with the items in the following list reversed: [1, 2, 3, 4, 5].

FWIW, this is the code that I used to solve the challenge:

class Stack:
    def __init__(self):
        self.items = []

    def is_empty(self):
        return self.items == []

    def push(self, item):
        self.items.append(item)

    def pop(self):
        return self.items.pop()

    def peek(self):
        last = len(self.items)-1
        return self.items[last]

    def size(self):
        return len(self.items)

stack = Stack()
int_list = []
for c in range(1, 6):
    stack.push(c)

reverse = []

for i in range(len(stack.items)):
    reverse.append(stack.pop())

print(reverse)

[5, 4, 3, 2, 1]

@calthoff
Copy link
Owner

@ILeftTheLaw You are completely correct. I just fixed it. Thanks so much for pointing this out. I should have you be the editor of my next book :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants