Commit 9db492f1 authored by Guido van Rossum's avatar Guido van Rossum

Consistently use a single leading underscore for instance variable

names.
parent 769fad63
...@@ -35,11 +35,11 @@ class NBest: ...@@ -35,11 +35,11 @@ class NBest:
# This does a very simple thing with sorted lists. For large # This does a very simple thing with sorted lists. For large
# N, a min-heap can be unboundedly better in terms of data # N, a min-heap can be unboundedly better in terms of data
# movement time. # movement time.
self.scores = [] self._scores = []
self.items = [] self._items = []
def __len__(self): def __len__(self):
return len(self.scores) return len(self._scores)
def capacity(self): def capacity(self):
return self._capacity return self._capacity
...@@ -48,7 +48,7 @@ class NBest: ...@@ -48,7 +48,7 @@ class NBest:
self.addmany([(item, score)]) self.addmany([(item, score)])
def addmany(self, sequence): def addmany(self, sequence):
scores, items, capacity = self.scores, self.items, self._capacity scores, items, capacity = self._scores, self._items, self._capacity
n = len(scores) n = len(scores)
for item, score in sequence: for item, score in sequence:
# When we're in steady-state, the usual case is that we're filled # When we're in steady-state, the usual case is that we're filled
...@@ -66,11 +66,11 @@ class NBest: ...@@ -66,11 +66,11 @@ class NBest:
assert n == len(scores) assert n == len(scores)
def getbest(self): def getbest(self):
result = zip(self.items, self.scores) result = zip(self._items, self._scores)
result.reverse() result.reverse()
return result return result
def pop_smallest(self): def pop_smallest(self):
if self.scores: if self._scores:
return self.items.pop(0), self.scores.pop(0) return self._items.pop(0), self._scores.pop(0)
raise IndexError("pop_smallest() called on empty NBest object") raise IndexError("pop_smallest() called on empty NBest object")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment