mirror of https://github.com/python/cpython.git
add an __len__ to Set and Stack
This commit is contained in:
parent
41d84631ba
commit
95b8614353
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue