Combining lists in python
问题 I am trying to combine 2 lists and want to form combinations. a = ['ibm','dell'] b = ['strength','weekness'] I want to form combinations like ['ibm strength','ibm weekness','dell strength','dell weakness'] . I tried to use zip or concatenated the lists. I also used itertools but it doesn't give me desired output. Please help. a = ['ibm','dell'] b = ['strength','weekness'] c = a + b itertools.combinations(c,2) for a in a: for b in b: print a +b 回答1: You're looking for product(). Try this: