Number Sequencing, Grouping and Filtering

2009-03-10 Thread flebber
Hi

I was hoping someone would be able to point me in the direction of
some good documentation regarding sequencing, grouping and filtering
and in which order they should be done.

As a small example it is easy to create the range of numbers 1 to 20.
But if I wanted to group all possible combinations of sets of 4
numbers within this range is there already an in uilt function for
this I am searching the module docs with number sequencing and
number grouping but cannot find info.

Then if I wanted to refine this results further eg no consecutive
numbers to be contained in sets. Is it best to create all sets and
then filter the sets for things matching this criteria or to set this
condition in a creation. Creating sets and then filtering would soon
become unwieldy with a larger range I would imagine..

An ideas, pointers to docs or better search terms to help me explore
this further would be appreciated.

Thanks Sayth
--
http://mail.python.org/mailman/listinfo/python-list


Re: Number Sequencing, Grouping and Filtering

2009-03-10 Thread Chris Rebert
On Tue, Mar 10, 2009 at 2:54 AM, flebber flebber.c...@gmail.com wrote:
 Hi

 I was hoping someone would be able to point me in the direction of
 some good documentation regarding sequencing, grouping and filtering
 and in which order they should be done.

 As a small example it is easy to create the range of numbers 1 to 20.
 But if I wanted to group all possible combinations of sets of 4
 numbers within this range is there already an in uilt function for
 this I am searching the module docs with number sequencing and
 number grouping but cannot find info.

I think itertools (http://docs.python.org/library/itertools.html)
combined with list comprehensions
(http://docs.python.org/dev/tutorial/datastructures.html#list-comprehensions)
should be able to accomplish what you want.

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Number Sequencing, Grouping and Filtering

2009-03-10 Thread flebber
On Mar 10, 8:54 pm, flebber flebber.c...@gmail.com wrote:
 Hi

 I was hoping someone would be able to point me in the direction of
 some good documentation regarding sequencing, grouping and filtering
 and in which order they should be done.

 As a small example it is easy to create the range of numbers 1 to 20.
 But if I wanted to group all possible combinations of sets of 4
 numbers within this range is there already an in uilt function for
 this I am searching the module docs with number sequencing and
 number grouping but cannot find info.

 Then if I wanted to refine this results further eg no consecutive
 numbers to be contained in sets. Is it best to create all sets and
 then filter the sets for things matching this criteria or to set this
 condition in a creation. Creating sets and then filtering would soon
 become unwieldy with a larger range I would imagine..

 An ideas, pointers to docs or better search terms to help me explore
 this further would be appreciated.

 Thanks Sayth

I have just found itertools is this acheivable using combinations()
and groupby() in itertools?

--
http://mail.python.org/mailman/listinfo/python-list


Re: Number Sequencing, Grouping and Filtering

2009-03-10 Thread Chris Rebert
On Tue, Mar 10, 2009 at 3:00 AM, flebber flebber.c...@gmail.com wrote:
 On Mar 10, 8:54 pm, flebber flebber.c...@gmail.com wrote:
 Hi

 I was hoping someone would be able to point me in the direction of
 some good documentation regarding sequencing, grouping and filtering
 and in which order they should be done.

 As a small example it is easy to create the range of numbers 1 to 20.
 But if I wanted to group all possible combinations of sets of 4
 numbers within this range is there already an in uilt function for
 this I am searching the module docs with number sequencing and
 number grouping but cannot find info.

 Then if I wanted to refine this results further eg no consecutive
 numbers to be contained in sets. Is it best to create all sets and
 then filter the sets for things matching this criteria or to set this
 condition in a creation. Creating sets and then filtering would soon
 become unwieldy with a larger range I would imagine..

 An ideas, pointers to docs or better search terms to help me explore
 this further would be appreciated.

 Thanks Sayth

 I have just found itertools is this acheivable using combinations()
 and groupby() in itertools?

Yes; indeed, those were the functions your post brought to mind and
which led me to suggest itertools.

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Number Sequencing, Grouping and Filtering

2009-03-10 Thread flebber
On Mar 10, 9:07 pm, Chris Rebert c...@rebertia.com wrote:
 On Tue, Mar 10, 2009 at 3:00 AM, flebber flebber.c...@gmail.com wrote:
  On Mar 10, 8:54 pm, flebber flebber.c...@gmail.com wrote:
  Hi

  I was hoping someone would be able to point me in the direction of
  some good documentation regarding sequencing, grouping and filtering
  and in which order they should be done.

  As a small example it is easy to create the range of numbers 1 to 20.
  But if I wanted to group all possible combinations of sets of 4
  numbers within this range is there already an in uilt function for
  this I am searching the module docs with number sequencing and
  number grouping but cannot find info.

  Then if I wanted to refine this results further eg no consecutive
  numbers to be contained in sets. Is it best to create all sets and
  then filter the sets for things matching this criteria or to set this
  condition in a creation. Creating sets and then filtering would soon
  become unwieldy with a larger range I would imagine..

  An ideas, pointers to docs or better search terms to help me explore
  this further would be appreciated.

  Thanks Sayth

  I have just found itertools is this acheivable using combinations()
  and groupby() in itertools?

 Yes; indeed, those were the functions your post brought to mind and
 which led me to suggest itertools.

 Cheers,
 Chris

 --
 I have a blog:http://blog.rebertia.com

the only issue i can see is that i am using python 2.54 currently as
ifelt it more supported by other programs than 2.6 or 3.0. After
searching it seems that itertools has had a upgrade in 2.61
--
http://mail.python.org/mailman/listinfo/python-list


Re: Number Sequencing, Grouping and Filtering

2009-03-10 Thread Raymond Hettinger
[flebber]
 the only issue i can see is that i am using python 2.54 currently as
 ifelt it more supported by other programs than 2.6 or 3.0. After
 searching it seems that itertools has had a upgrade in 2.61

All of the itertools include pure python equivalents in their docs,
so it should be possible to backport them to 2.5 by cutting and
pasting the code equivalent.


Raymond

-
def combinations(iterable, r):
# combinations('ABCD', 2) -- AB AC AD BC BD CD
# combinations(range(4), 3) -- 012 013 023 123
pool = tuple(iterable)
n = len(pool)
indices = range(r)
yield tuple(pool[i] for i in indices)
while 1:
for i in reversed(range(r)):
if indices[i] != i + n - r:
break
else:
return
indices[i] += 1
for j in range(i+1, r):
indices[j] = indices[j-1] + 1
yield tuple(pool[i] for i in indices)


--
http://mail.python.org/mailman/listinfo/python-list