Input: [1, 2, 3] [a, b]
Expected Output: [(1,a),(1,b),(2,a),(2,b),(3,a),(3,b)]
Run Code Online (Sandbox Code Playgroud)
这是有效的,但是没有 if 语句有更好的方法吗?
[(x,y) for (x,y) in list(combinations(chain(a,b), 2)) if x in a and y in b]
Run Code Online (Sandbox Code Playgroud)