In need of a binge-and-purge idiom

Magnus Lie Hetland mlh at furu.idi.ntnu.no
Tue Mar 25 01:22:42 CET 2003


In article <698f09f8.0303232304.608bc8cf at posting.google.com>, Jeremy
Fincher wrote:
>Maybe something like this can work?
[snip]
>
>def itersplit(iterable, isSeparator):
>    acc = []
>    for element in iterable:
>        if isSeparator(element):
>            yield acc
>            acc = []
>        else:
>            acc.append(element)
>    yield acc

You should add "if acc" before you yield acc -- I don't want an empty
acc (that only means several separators in a row -- which amounts to a
single separator in my case). And, with that statement in place, you'd
get the same duplication as before, as far as I can see. What is new
about this (except putting it inside a generator)?

Thanks for the input, though.

-- 
Magnus Lie Hetland               "Nothing shocks me. I'm a scientist." 
http://hetland.org                                   -- Indiana Jones




More information about the Python-list mailing list