In need of a binge-and-purge idiom
Manuel Garcia
news at manuelmgarcia.com
Tue Mar 25 14:54:04 EST 2003
On Sun, 23 Mar 2003 14:19:53 -0500, "Tim Peters"
<tim_one at email.msn.com> wrote:
>If the code made sense <wink>, something like
>
>def terminated_iterator(iterable, a_seperator):
> for element in iterable:
> yield element
> yield a_separator
>
>would produce the original sequence, then tack a_separator on to the end.
Isn't it a general rule that terminators are easier to work with than
separators? I remember some programming guru saying this (Jon
Bentley?) I think it was Pascal's use of separators between
statements that convinced Dennis Ritchie to use terminators instead.
When I have to deal with separators, I always tack an extra one on the
end, using a trick like the one above, or a simple append or
concatenation. This is usually good to make a boolean or repeated
code vanish. For string processing, I usually throw an extra one on
the front too, for good luck.
Separator is also harder to spell than terminator. ;-)
Manuel
More information about the Python-list
mailing list