Conditional Cartesian product of lists in itertools
问题 I have four lists: LISTA = ['A1', 'A2'] LISTB = ['B1_C', 'B2_D'] LISTC = ['C1', 'C2'] LISTD = ['D1', 'D2'] I'd like to get the Cartesian product of LISTA and LISTB , and then depending on the value of B, I'd like to add either the product of C, or the product of D. (A1 B1_C C1) (A1 B1_C C2) (A2 B1_C C1) (A2 B1_C C2) (A1 B2_D D1) (A1 B2_D D2) (A2 B2_D D1) (A2 B2_D D2) I can get the first part with itertools.product(LISTA, LISTB) , but I've been looking through itertools for how to achieve the