add an __len__ to Set and Stack

This commit is contained in:
Jeremy Hylton 2000-02-10 20:54:27 +00:00
parent 41d84631ba
commit 95b8614353
2 changed files with 8 additions and 0 deletions

View File

@ -1,6 +1,8 @@
class Set:
def __init__(self):
self.elts = {}
def __len__(self):
return len(self.elts)
def add(self, elt):
self.elts[elt] = elt
def items(self):
@ -14,6 +16,8 @@ class Stack:
def __init__(self):
self.stack = []
self.pop = self.stack.pop
def __len__(self):
return len(self.stack)
def push(self, elt):
self.stack.append(elt)
def top(self):

View File

@ -1,6 +1,8 @@
class Set:
def __init__(self):
self.elts = {}
def __len__(self):
return len(self.elts)
def add(self, elt):
self.elts[elt] = elt
def items(self):
@ -14,6 +16,8 @@ class Stack:
def __init__(self):
self.stack = []
self.pop = self.stack.pop
def __len__(self):
return len(self.stack)
def push(self, elt):
self.stack.append(elt)
def top(self):