Re: [Tutor] numbers and ranges

2007-06-05 Thread Kent Johnson
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) >

Re: [Tutor] numbers and ranges

2007-05-27 Thread Kent Johnson
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

Re: [Tutor] numbers and ranges

2007-05-27 Thread Jon Crump
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

Re: [Tutor] numbers and ranges

2007-05-27 Thread Kent Johnson
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

Re: [Tutor] numbers and ranges

2007-05-27 Thread Bob Gailer
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