Newbie question - better way to do this?
Paul Rubin
http
Sun May 27 23:41:35 EDT 2007
Eric <venner at gmail.com> writes:
> 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).
As another poster suggested, use itertools.groupby:
for cap,g in groupby(words, firstIsCapitalized):
if cap: doSomething(list(g))
This will handle sequences at the the end words just like other sequences.
More information about the Python-list
mailing list