how to get all possible combination of items from 2-dimensional list in 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. 回答1: You need itertools.product(): >>> list