赞
踩
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)]
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。