python-分组列表元素

python-分组列表元素,python,python-3.x,Python,Python 3.x,我想将列表中的每个元素与列表中的所有其他元素分组 例如— l1 = [1,2,3] l2 = [(1,2),(1,3),(2,3)] 我尝试使用zip: l2 = list(zip(l1,l1[1:])) 但它给了我: l2 = [(1, 2), (2, 3)] 期望输出: [(1,2),(1,3),(2,3)] 为了 这就是为什么: @巴尔加夫罗谢谢 [1,2,3] >>> l1 = [1,2,3] >>> from itertools impor

我想将列表中的每个元素与列表中的所有其他元素分组

例如—

l1 = [1,2,3]
l2 = [(1,2),(1,3),(2,3)]
我尝试使用zip:

l2 = list(zip(l1,l1[1:]))
但它给了我:

l2 = [(1, 2), (2, 3)]
期望输出:

[(1,2),(1,3),(2,3)]
为了

这就是为什么:

@巴尔加夫罗谢谢
[1,2,3]
>>> l1 = [1,2,3]
>>> from itertools import combinations
>>> list(combinations(l1,2))
[(1, 2), (1, 3), (2, 3)]