How to turn a list of iterators into all possible lists using those iterators [duplicate]












0
















This question already has an answer here:




  • All combinations of a list of lists

    6 answers




I have a list of iterators, such as l = [range(1), range(2), range(3)] and each iterator iterates over the possibilities that could be in that slot.



However, I don't know how long the list is going to be.
In this case, to get what I want, I can easily do [[val1, val2, val3] for val1 in l[0] for val2 in l[1] for val3 in l[2]].



I've been looking a lot at itertools, and couldn't see anything that matched this pattern.



What function can take in a list of iterators and generate a list of all the possibilities for lists where each value in the list is a value of one of the generators in the slots?










share|improve this question













marked as duplicate by Jean-François Fabre python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 8:14


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • range is not an interator.

    – DYZ
    Nov 25 '18 at 8:09











  • True. Thank you for catching that.

    – Pro Q
    Nov 25 '18 at 10:26
















0
















This question already has an answer here:




  • All combinations of a list of lists

    6 answers




I have a list of iterators, such as l = [range(1), range(2), range(3)] and each iterator iterates over the possibilities that could be in that slot.



However, I don't know how long the list is going to be.
In this case, to get what I want, I can easily do [[val1, val2, val3] for val1 in l[0] for val2 in l[1] for val3 in l[2]].



I've been looking a lot at itertools, and couldn't see anything that matched this pattern.



What function can take in a list of iterators and generate a list of all the possibilities for lists where each value in the list is a value of one of the generators in the slots?










share|improve this question













marked as duplicate by Jean-François Fabre python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 8:14


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • range is not an interator.

    – DYZ
    Nov 25 '18 at 8:09











  • True. Thank you for catching that.

    – Pro Q
    Nov 25 '18 at 10:26














0












0








0









This question already has an answer here:




  • All combinations of a list of lists

    6 answers




I have a list of iterators, such as l = [range(1), range(2), range(3)] and each iterator iterates over the possibilities that could be in that slot.



However, I don't know how long the list is going to be.
In this case, to get what I want, I can easily do [[val1, val2, val3] for val1 in l[0] for val2 in l[1] for val3 in l[2]].



I've been looking a lot at itertools, and couldn't see anything that matched this pattern.



What function can take in a list of iterators and generate a list of all the possibilities for lists where each value in the list is a value of one of the generators in the slots?










share|improve this question















This question already has an answer here:




  • All combinations of a list of lists

    6 answers




I have a list of iterators, such as l = [range(1), range(2), range(3)] and each iterator iterates over the possibilities that could be in that slot.



However, I don't know how long the list is going to be.
In this case, to get what I want, I can easily do [[val1, val2, val3] for val1 in l[0] for val2 in l[1] for val3 in l[2]].



I've been looking a lot at itertools, and couldn't see anything that matched this pattern.



What function can take in a list of iterators and generate a list of all the possibilities for lists where each value in the list is a value of one of the generators in the slots?





This question already has an answer here:




  • All combinations of a list of lists

    6 answers








python list iterator






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 7:59









Pro QPro Q

93821329




93821329




marked as duplicate by Jean-François Fabre python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 8:14


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Jean-François Fabre python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 8:14


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • range is not an interator.

    – DYZ
    Nov 25 '18 at 8:09











  • True. Thank you for catching that.

    – Pro Q
    Nov 25 '18 at 10:26



















  • range is not an interator.

    – DYZ
    Nov 25 '18 at 8:09











  • True. Thank you for catching that.

    – Pro Q
    Nov 25 '18 at 10:26

















range is not an interator.

– DYZ
Nov 25 '18 at 8:09





range is not an interator.

– DYZ
Nov 25 '18 at 8:09













True. Thank you for catching that.

– Pro Q
Nov 25 '18 at 10:26





True. Thank you for catching that.

– Pro Q
Nov 25 '18 at 10:26












1 Answer
1






active

oldest

votes


















0














As I was typing up this question, I realized that there is in fact an itertools function that accomplishes this.



list(itertools.product(*l)) does the trick.



I figure I'll just post this as a self-answered question in case someone else has similar terminology.






share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    As I was typing up this question, I realized that there is in fact an itertools function that accomplishes this.



    list(itertools.product(*l)) does the trick.



    I figure I'll just post this as a self-answered question in case someone else has similar terminology.






    share|improve this answer




























      0














      As I was typing up this question, I realized that there is in fact an itertools function that accomplishes this.



      list(itertools.product(*l)) does the trick.



      I figure I'll just post this as a self-answered question in case someone else has similar terminology.






      share|improve this answer


























        0












        0








        0







        As I was typing up this question, I realized that there is in fact an itertools function that accomplishes this.



        list(itertools.product(*l)) does the trick.



        I figure I'll just post this as a self-answered question in case someone else has similar terminology.






        share|improve this answer













        As I was typing up this question, I realized that there is in fact an itertools function that accomplishes this.



        list(itertools.product(*l)) does the trick.



        I figure I'll just post this as a self-answered question in case someone else has similar terminology.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 7:59









        Pro QPro Q

        93821329




        93821329

















            Popular posts from this blog

            Wiesbaden

            Marschland

            To store a contact into the json file from server.js file using a class in NodeJS