Sequence splitting
Mel
mwilson at the-wire.com
Fri Jul 3 15:08:35 EDT 2009
Steven D'Aprano wrote:
> The most important difference between my suggestion and that of the OP is
> that he limited the key function to something which returns a truth
> value, while I'm looking for something more general which can split the
> input into an arbitrary number of collated sublists.
Generally along the lines of
def scatter (seq, criterion):
lists = {}
for s in seq:
lists.setdefault (criterion (s), []).append (s)
return lists
modulo a defaultdict or some such ?
Mel.
>
>
>
More information about the Python-list
mailing list