def read_word(self): if self._index >= self._len: self._eof = True return False self._nxt = self._list[self._index] self._key = Alphabet.sortkey(self._nxt) self._index += 1 return True
def read_word(self): """ Read lines until we have a legal word or EOF """ while True: try: line = next(self._fin).strip() except StopIteration: # We're done with this file self._eof = True return False if line and len(line) < MAXLEN: # Valid word self._nxt = line self._key = Alphabet.sortkey(line) return True
def read_word(self): """ Read lines until we have a legal word or EOF """ while True: try: line = self._fin.next() except StopIteration: # We're done with this file self._eof = True return False if line.endswith(u'\r\n'): # Cut off trailing CRLF (Windows-style) line = line[0:-2] elif line.endswith(u'\n'): # Cut off trailing LF (Unix-style) line = line[0:-1] if line and len(line) < MAXLEN: # Valid word self._nxt = line self._key = Alphabet.sortkey(line) return True
def done(self): """ Called when the whole navigation is done """ self._result.sort(key=lambda x: (-len(x), Alphabet.sortkey(x)))
def done(self): """ Called when the whole navigation is done """ self._result.sort(key = lambda x: (-len(x), Alphabet.sortkey(x)))
def _sorted(l): """ Return a list of (prefix, node) tuples sorted by prefix """ return sorted(l, key=lambda x: Alphabet.sortkey(x[0]))
def _sorted(l): """ Return a list of (prefix, node) tuples sorted by prefix """ return sorted(l, key = lambda x: Alphabet.sortkey(x[0]))