当前位置:   article > 正文

python遍历二维列表的方法解决问题,如何从python中的二维列表中获取所有可能的项目组合?...

python 五个点放进二维阵列 遍历所有可能

I didn't find a better way to phrase this question in the title. If you can, please edit.

I have a list of lists like this:

a = [['a','b'],[1,2]]

now, I'd like a function that spits out all possible combination like this:

[['a',1],['a',2],['b',1],['b',2]]

where nor the number of lists in a is known in advance, nor is the length of each of the sub lists known in advance, but all the combinations that come out should contain 1 item from every sublist.

解决方案>>> list(itertools.product(*a))

[('a', 1), ('a', 2), ('b', 1), ('b', 2)]

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/201725
推荐阅读
相关标签
  

闽ICP备14008679号