On May 28, 12:46 am, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Sun, 27 May 2007 06:44:01 -0700, Eric wrote:
> > words is a big long array of strings.  What I want to do is find
> > consecutive sequences of words that have the first letter capitalized,
> > and then call doSomething on them.  (And you can ignore the fact that
> > it won't find a sequence at the very end of words, that is fine for my
> > purposes).
>
> Assuming the list of words will fit into memory, and you can probably
> expect to fit anything up to millions of words comfortably into memory,
> something like this might be suitable:
>
> list_of_words = "lots of words go here".split()
>
> accumulator = []
> for word in list_of_words:
>     if word.istitle():
>         accumulator.append(word)
>     else:
>         doSomething(accumulator)
>         accumulator = []
>
Bzzzt. Needs the following code at the end:
if accumulator:
    doSomething(accumulator)

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to