very well done..
But I thought it may require a little bit of change in the proposed code.. :)
def _revision_list_with_ranges_to_list_without_ranges(revision_list):
for revision in revision_list.split(','):
if '-' in str(revision):
from_revision, _, to_revision = str(revision).partition('-')
for revision_in_range in range(int(from_revision),
int(to_revision)+1):
yield revision_in_range
else:
yield int(revision)
cheers:
suneel kingrani
________________________________
From: Simon Brunning <[email protected]>
To: Seldon <[email protected]>
Cc: [email protected]
Sent: Fri, 25 February, 2011 10:36:10 PM
Subject: Re: Parsing numeric ranges
On 25 February 2011 09:27, Seldon <[email protected]> wrote:
> Hi all,
> I have to convert integer ranges expressed in a popular "compact" notation
> (e.g. 2, 5-7, 20-22, 41) to a the actual set of numbers (i.e.
> 2,5,7,20,21,22,41).
>
> Is there any library for doing such kind of things or I have to write it
> from scratch ?
I dredged this out:
def _revision_list_with_ranges_to_list_without_ranges(revision_list):
'''Convert a revision list with ranges (e.g. '1,3,5-7') to a
simple list without ranges (1,3,5,6,7)'''
for revision in revision_list:
if '-' in revision:
from_revision, _, to_revision = revision.partition('-')
for revision_in_range in range(int(from_revision),
int(to_revision)+1):
yield revision_in_range
else:
yield int(revision)
--
Cheers,
Simon B.
--
http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list