我想将列表中的所有元素与列表中的所有其他元素分组
代表前 -
l2 = list(zip(l1,l1[1:]))
我尝试使用zip:
l2 = [(1, 2), (2, 3)]
但它给了我:
[(1,2),(1,3),(2,3)]
期望的输出:
[1,2,3]
代表
Uncaught Error: [$injector:modulerr] Failed to instantiate module moduleApp due to:
Error: [$injector:modulerr] Failed to instantiate module app.module due to:
Error: [$injector:nomod] Module 'app.module' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
答案 0 :(得分:10)
它是itertools.combinations的用途:
>>> l1 = [1,2,3]
>>> from itertools import combinations
>>> list(combinations(l1,2))
[(1, 2), (1, 3), (2, 3)]