From 954c97041509043767b26755b18b2f7de4066ed1 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 4 Nov 2014 01:07:08 +1100 Subject: [PATCH] * Add __iter__ method to tokens --- spacy/tokens.pyx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spacy/tokens.pyx b/spacy/tokens.pyx index eafa65194..25bfdc10e 100644 --- a/spacy/tokens.pyx +++ b/spacy/tokens.pyx @@ -59,6 +59,10 @@ cdef class Tokens: bounds_check(i, self.length, PADDING) return Token(self._string_store, i, self.idx[i], self.pos[i], self.lex[i][0]) + def __iter__(self): + for i in range(self.length): + yield self[i] + def __len__(self): return self.length