Does that help How can I get all the combinations of a list with duplicates. By duplicates I mean an element with itself. I am building a symmetric matrix. , It sounds like you're looking for expand.grid instead of combn: code :
expand.grid(names.list, names.list)
# Var1 Var2
# 1 A A
# 2 B A
# 3 C A
# 4 A B
# 5 B B
# 6 C B
# 7 A C
# 8 B C
# 9 C C
library(gtools)
combinations(3, 2, names.list, repeats = TRUE)
# [,1] [,2]
# [1,] "A" "A"
# [2,] "A" "B"
# [3,] "A" "C"
# [4,] "B" "B"
# [5,] "B" "C"
# [6,] "C" "C"
Share :

two element combinations of the elements of a list inside lisp (without duplicates)
By : Thinh Nguyen
Date : March 29 2020, 07:55 AM
hope this fix your issue From any given list in lisp, I want to get the two element combinations of the elements of that list without having duplicate combinations ( meaning (a b) = (b a) and one should be removed) , Assuming I'm understanding you correctly, I'd use mapcar and friends. code :
(defun pairwith (elem lst)
(mapcar (lambda (a) (list elem a)) lst))
(defun uniquepairs (lst)
(mapcon (lambda (rest) (pairwith (car rest) (cdr rest)))
(removeduplicates lst)))
CLUSER> (uniquepairs (list 1 2 3 4 5))
((1 2) (1 3) (1 4) (1 5) (2 3) (2 4) (2 5) (3 4) (3 5) (4 5))
CLUSER> (uniquepairs (list :a :b :c :a :b :d))
((:C :A) (:C :B) (:C :D) (:A :B) (:A :D) (:B :D))
(defun uniquepairs (lst)
(loop for (a . rest) on (removeduplicates lst)
append (pairwith a rest)))

FAST unique combinations (from list with duplicates) WITHOUT LOOKUPS
By : Eric Noh
Date : March 29 2020, 07:55 AM
around this issue Instead of postprocessing/filtering your output, you can preprocess your input list. This way, you can avoid generating duplicates in the first place. Preprocessing involves either sorting (or using a collections.Counter on) the input. One possible recursive realization is: code :
def subbags(bag, k):
a = sorted(bag)
n = len(a)
sub = []
def index_of_next_unique_item(i):
j = i + 1
while j < n and a[j] == a[i]:
j += 1
return j
def combinate(i):
if len(sub) == k:
yield tuple(sub)
elif n  i >= k  len(sub):
sub.append(a[i])
yield from combinate(i + 1)
sub.pop()
yield from combinate(index_of_next_unique_item(i))
yield from combinate(0)
bag = [1, 2, 3, 1, 2, 1]
k = 3
i = 1
print(sorted(bag), k)
print('')
for i, subbag in enumerate(subbags(bag, k)):
print(subbag)
print('')
print(i + 1)
[1, 1, 1, 2, 2, 3] 3

(1, 1, 1)
(1, 1, 2)
(1, 1, 3)
(1, 2, 2)
(1, 2, 3)
(2, 2, 3)

6

Generating a list of combinations from a list of strings with a common separator without reverse duplicates
By : alluniquepainting
Date : March 29 2020, 07:55 AM
I hope this helps . Make sure currPosition is always smaller than nextPosition: Maybe by changing code :
if currPosition != nextPosition:
if currPosition < nextPosition:

All 3 value combinations of a list without duplicates
By : one.zhao
Date : March 29 2020, 07:55 AM
hope this fix your issue Is there a way to get all possible 3 value combinations out of something like: , Yes you can try this: code :
import itertools
a = ['1','2','3']
for i in itertools.permutations(a):
print(''.join(i))

How to find all possible combinations from a list with only two elements and no duplicates with Python?
By : Bortolettot
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You can try this, as it makes use of combinations so import it from itertools like this: code :
from itertools import combinations
#also it's good practice not to use list, so for sake of it call it something else
listPlayers = ["player1", "player2", "player3"]
getPairPlayers = sorted(map(sorted, combinations(set(listPlayers), 2)))
print(getPairPlayers)
[['player1', 'player2'], ['player1', 'player3'], ['player2', 'player3']]

