Re: Refactor a buffered class...

2006-09-13 Thread lh84777
thanks a lot to all, i help me to learn a lot ! (i finally use the generator trick, it is great...) best regards. -- http://mail.python.org/mailman/listinfo/python-list

Re: Refactor a buffered class...

2006-09-07 Thread George Sakkis
Michael Spencer wrote: > I think the two versions below each give the 'correct' output wrt to the OP's > single test case. I measure chunkerMS2 to be faster than chunkerGS2 across > all > chunk sizes, but this is all about the joins. > > I conclude that chunkerGS's deque beats chunkerMS's list f

Re: Refactor a buffered class...

2006-09-07 Thread Michael Spencer
George Sakkis wrote: > Michael Spencer wrote: >> George Sakkis wrote: >>> Michael Spencer wrote: >>> def chunker(s, chunk_size=3, sentry=".", keep_first = False, keep_last = False): buffer=[] >> ... >>> And here's a (probably) more efficient version, using a deque as a >>> buff

Re: Refactor a buffered class...

2006-09-07 Thread George Sakkis
Michael Spencer wrote: > George Sakkis wrote: > > Michael Spencer wrote: > > > >> Here's a small update to the generator that allows optional handling of > >> the head > >> and the tail: > >> > >> def chunker(s, chunk_size=3, sentry=".", keep_first = False, keep_last = > >> False): > >> buff

Re: Refactor a buffered class...

2006-09-06 Thread Paul Rubin
[EMAIL PROTECTED] writes: > for: s = "this . is a . test to . check if it . works . well . it looks > . like ." > the output should be (if grouping by 3) like: > > => this . > => this . is a . I don't understand, you mean you have all the items in advance? Can't you do something like this? I got

Re: Refactor a buffered class...

2006-09-06 Thread Michael Spencer
George Sakkis wrote: > Michael Spencer wrote: > >> Here's a small update to the generator that allows optional handling of the >> head >> and the tail: >> >> def chunker(s, chunk_size=3, sentry=".", keep_first = False, keep_last = >> False): >> buffer=[] ... > > And here's a (probably) mor

Re: Refactor a buffered class...

2006-09-06 Thread George Sakkis
Michael Spencer wrote: > Here's a small update to the generator that allows optional handling of the > head > and the tail: > > def chunker(s, chunk_size=3, sentry=".", keep_first = False, keep_last = > False): > buffer=[] > sentry_count = 0 > > for item in s: > buffer.ap

Re: Refactor a buffered class...

2006-09-06 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > actually for the example i have used only one sentry condition by they > are more numerous and complex, also i need to work on a huge amount on > data (each word are a line with many features readed from a file) An open (text) file is a line-based iterator that can be fed

Re: Refactor a buffered class...

2006-09-06 Thread lh84777
oops > 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 . well . it looks like . it looks like . -- http://mail.python.org/mailman/listinfo/python-list

Re: Refactor a buffered class...

2006-09-06 Thread lh84777
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

Re: Refactor a buffered class...

2006-09-06 Thread lh84777
Michael Spencer a écrit : > If you just need to 'walk across a list of items', then your buffer class and > helper function seem unnecessary complex. A generator would do the trick, > something like: actually for the example i have used only one sentry condition by they are more numerous and co

Re: Refactor a buffered class...

2006-09-06 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > Hello, > > i'm looking for this behaviour and i write a piece of code which works, > but it looks odd to me. can someone help me to refactor it ? > > i would like to walk across a list of items by series of N (N=3 below) > of these. i had explicit mark of end of a seque

Refactor a buffered class...

2006-09-06 Thread lh84777
Hello, i'm looking for this behaviour and i write a piece of code which works, but it looks odd to me. can someone help me to refactor it ? i would like to walk across a list of items by series of N (N=3 below) of these. i had explicit mark of end of a sequence (here it is '.') which may be any l