From 95b8614353eee05f350c794a0aa37cab39794eed Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Thu, 10 Feb 2000 20:54:27 +0000 Subject: add an __len__ to Set and Stack --- Lib/compiler/misc.py | 4 ++++ Tools/compiler/compiler/misc.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Lib/compiler/misc.py b/Lib/compiler/misc.py index 0dc6422..a281c10 100644 --- a/Lib/compiler/misc.py +++ b/Lib/compiler/misc.py @@ -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): diff --git a/Tools/compiler/compiler/misc.py b/Tools/compiler/compiler/misc.py index 0dc6422..a281c10 100644 --- a/Tools/compiler/compiler/misc.py +++ b/Tools/compiler/compiler/misc.py @@ -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): -- cgit v0.12