Kent Johnson wrote:
Here is a solution that uses a generator to create the ranges:
>
> def ranges(data):
> i = iter(data)
> first = last = i.next()
> try:
> while 1:
> next = i.next()
> if next > last+1:
> yield (first, last)
>
Jon Crump wrote:
> Kent,
>
> That's damned clever! Your solution hovers right at the limit of my
> understanding, but the print statements illustrate very clearly the
> operation of the function.
You're welcome! I recently wrote some notes about iterators and
generators that might help your un
Kent,
That's damned clever! Your solution hovers right at the limit of my
understanding, but the print statements illustrate very clearly the
operation of the function.
Many thanks!
Jon
On Sun, 27 May 2007, Kent Johnson wrote:
>> Here's a puzzle that should be simple, but I'm so used to words
Jon Crump wrote:
> Dear all,
>
> Here's a puzzle that should be simple, but I'm so used to words that
> numbers tend to baffle me.
>
> I've got fields that look something like this:
> 1942. Oct. 1,3,5,7,8,9,10
>
> I need to parse them to obtain something like this:
>
>
>
>
>
> The xml repr
Jon Crump wrote:
> Dear all,
>
> Here's a puzzle that should be simple, but I'm so used to words that
> numbers tend to baffle me.
>
> I've got fields that look something like this:
> 1942. Oct. 1,3,5,7,8,9,10
>
> I need to parse them to obtain something like this:
>
>
>
>
>
> The xml represen