pick combinations from multiple lists

后端 未结 2 1152
长情又很酷
长情又很酷 2020-12-17 10:26

I am new to python and I am struggling to form a combination of multiple lists. So, I have three (and possible more) looking like this:

uk_rock_stars=[1,2,3,         


        
2条回答
  •  余生分开走
    2020-12-17 11:07

    I think this is what you're looking for:

    import itertools
    comb = itertools.product(uk_rock_stars, uk_pop_stars, us_stars)
    

    It will give you an iterator object, which may or may not be what you want. To convert it to a normal list, just use this:

    comb = list(comb)
    

提交回复
热议问题