小编Kyl*_*e K的帖子

2个列表的组合

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)

python combinations list

5
推荐指数
1
解决办法
8282
查看次数

标签 统计

combinations ×1

list ×1

python ×1