Stack implementation in Python3

I'm learning Python by implementing the commonly used data structures. Here's my Stack implementation,

class Node:     def __init__(self, value=None, next=None):         self.value = value         self.next = next  from node import Node   class Stack:     def __init__(self):         self.top = None         self.size = 0      def push(self, item):         curr = Node(item)         self.size += 1         if self.top is None:             self.top = curr         else:             curr.next = self.top             self.top = curr      def peek(self):         return self.top.value      def pop(self):         if self.top is None:             raise Exception("Nothing to pop.")         curr = self.top         self.top = self.top.next         self.size -= 1         return curr      def __sizeof__(self):         return self.size      def is_empty(self):         return self.size == 0;      def __str__(self):         curr = self.top         while curr:             print(curr.value, end=' ')             curr = curr.next 

Invite comments. My primary language is Java, thus would like to know if I'm being Pythonic enough. Any means to better up will be appreciated.

Replay

Category: python Time: 2016-07-29 Views: 0
Tags: python stack

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.208 (s). 12 q(s)