grouping a flat list of number by range

Jim Segrave jes at
Fri Jun 2 13:44:33 CEST 2006

In article <1149232358.817706.92680 at>,
Paddy <paddy3118 at> wrote:
>John Machin wrote:
>> On 2/06/2006 8:36 AM, Paddy wrote:
>> Oh the siren call of every new feature in the language!
>> enumerate() just to get a first-time test, and then botch it??
>> Read the following; the replacement version uses a simple old-fashioned
>> inelegant flag, works with an empty sequence, and doesn't depend on the
>> input being sliceable or indexable.
>> HTH,
>> John
>Thanks, un-botchable John. What if the poster doesn't send a null list?
>What if the correct result for a null list is "spam"; or an exception?
>What if.... ... we toned down the language?

I'd still rate Ben Cartwright's solution as the best. The one I posted
tried to do the same, but I didn't see the right way to iterate over
the supplied list inside the function, wheras he did. It's short,
simple and correct.

If you really wanted to return 'spam' or an exception in his solution,
it's a simple if statement at the start of the function.

Jim Segrave           (jes at

More information about the Python-list mailing list