python - grouping list elements -


this question has answer here:

i want group every element in list other elements in list

for ex -

l1 = [1,2,3] l2 = [(1,2),(1,3),(2,3)] 

i try using zip:

l2 = list(zip(l1,l1[1:])) 

but gives me:

l2 = [(1, 2), (2, 3)] 

desired output:

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

for

[1,2,3] 

its itertools.combinations :

>>> l1 = [1,2,3] >>> itertools import combinations >>> list(combinations(l1,2)) [(1, 2), (1, 3), (2, 3)] 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -