Here is another version, class ChunkeredBuffer: def __init__(self): self.buffer = [] self.sentries = [] def append(self, item): self.buffer.append(item) def chunk(self, chunkSize, keepFirst = False): self.sentries.append(len(self.buffer)) forget = self.sentries[:-chunkSize] if not keepFirst and len(self.sentries) < chunkSize: return if forget != []: last = forget[-1] self.buffer = self.buffer[last:] self.sentries = [x - last for x in self.sentries[1:]] print >> sys.stderr, self.sentries, len(self.sentries), forget return self.buffer
but i was wondering how i could add, the last items if needed: it looks . like . like . to the previous: this . this . is a . this . is a . test to . is a . test to . check if it . test to . check if it . works . check if it . works . well . works . well . it looks like . to have: this . this . is a . this . is a . test to . is a . test to . check if it . test to . check if it . works . check if it . works . well . works . well . it looks like . it looks . like . like . -- http://mail.python.org/mailman/listinfo/python-list