ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 21 Apr 2021 19:12:26 +0200How to create lists of n-tuples efficiently?https://ask.sagemath.org/question/56756/how-to-create-lists-of-n-tuples-efficiently/The ultimate problem I'm trying to solve, is that given two integers *p* and *q*, I would like to create a list (say "*List1*"), whose entries are (all of the) lists of length *2q* which:
1) For all *L* in *List1*, the first *q* entries are between 0 and *pq-1* (inclusive), and the next *q* entries are between *pq* and *2pq-1* (inclusive)
2) For all *L* in *List1*, the entries are strictly increasing, that is for all *1<=i<=2pq*, *L[i] < L[i+1]*
I have a way of doing this which is very "brute force", where I first construct the list of lists of length 1, then the list of lists of length 2, etc.
I'm imagining (hoping) there exists some way for me to just iterate over all *2q* -tuples (without repetition) of numbers from 1 to *2pq* Something along the lines of
List1 = []
for x in 2q-tuples of [0, 1, 2, ..., 2pq-1]:
if x satisfies 1) and 2):
List1.append(x)
I suppose I would want to convert x to a list before appending to List1, or many there's some way to iterate over lists instead of tuples. That's not so important, I just want an efficient way to construct these lists.sum8tionWed, 21 Apr 2021 19:12:26 +0200https://ask.sagemath.org/question/56756/