Skip to main content
deleted 55 characters in body
Source Link
Pluviophile
  • 143
  • 1
  • 2
  • 9

I tried to get the all unique pair combinations from a list.

Here is what I have done so far,

import itertools

# Unique Combination Pairs for list of elements
def uniqueCombinations(list_elements):
    l = list(itertools.combinations(list_elements, 2))
    s = set(l)
    # print('actual', len(l), l)
    return list(s)

Test Case 1

sample = ["apple", "orange", "banana", "grapes", "mango"]
uniqueCombinations(sample)

Output

[('apple', 'banana'),
 ('orange', 'mango'),
 ('orange', 'grapes'),
 ('apple', 'grapes'),
 ('orange', 'banana'),
 ('apple', 'mango'),
 ('grapes', 'mango'),
 ('apple', 'orange'),
 ('banana', 'mango'),
 ('banana', 'grapes')]

Test Case 2The input will be unique strings of list. Assume that duplicate elements will not be passed.

uniqueCombinations(['apple', 'orange', 'apple'])
[('apple', 'orange'), ('apple', 'apple'), ('orange', 'apple')]

Is there a better / more elegant / more accurate way to do this??

I tried to get the all unique pair combinations from a list.

Here is what I have done so far,

import itertools

# Unique Combination Pairs for list of elements
def uniqueCombinations(list_elements):
    l = list(itertools.combinations(list_elements, 2))
    s = set(l)
    # print('actual', len(l), l)
    return list(s)

Test Case 1

sample = ["apple", "orange", "banana", "grapes", "mango"]
uniqueCombinations(sample)

Output

[('apple', 'banana'),
 ('orange', 'mango'),
 ('orange', 'grapes'),
 ('apple', 'grapes'),
 ('orange', 'banana'),
 ('apple', 'mango'),
 ('grapes', 'mango'),
 ('apple', 'orange'),
 ('banana', 'mango'),
 ('banana', 'grapes')]

Test Case 2

uniqueCombinations(['apple', 'orange', 'apple'])
[('apple', 'orange'), ('apple', 'apple'), ('orange', 'apple')]

Is there a better / more elegant / more accurate way to do this??

I tried to get the all unique pair combinations from a list.

Here is what I have done so far,

import itertools

# Unique Combination Pairs for list of elements
def uniqueCombinations(list_elements):
    l = list(itertools.combinations(list_elements, 2))
    s = set(l)
    # print('actual', len(l), l)
    return list(s)

Test Case

sample = ["apple", "orange", "banana", "grapes", "mango"]
uniqueCombinations(sample)

Output

[('apple', 'banana'),
 ('orange', 'mango'),
 ('orange', 'grapes'),
 ('apple', 'grapes'),
 ('orange', 'banana'),
 ('apple', 'mango'),
 ('grapes', 'mango'),
 ('apple', 'orange'),
 ('banana', 'mango'),
 ('banana', 'grapes')]

The input will be unique strings of list. Assume that duplicate elements will not be passed.

Is there a better / more elegant / more accurate way to do this??

added 172 characters in body
Source Link
Pluviophile
  • 143
  • 1
  • 2
  • 9

I tried to get the all unique pair combinations from a list.

Here is what I have done so far,

import itertools

# Unique Combination Pairs for list of elements
def uniqueCombinations(list_elements):
    l = list(itertools.combinations(list_elements, 2))
    s = set(l)
    # print('actual', len(l), l)
    return list(s)

Test Case 1

sample = ["apple", "orange", "banana", "grapes", "mango"]
uniqueCombinations(sample)

Output

[('apple', 'banana'),
 ('orange', 'mango'),
 ('orange', 'grapes'),
 ('apple', 'grapes'),
 ('orange', 'banana'),
 ('apple', 'mango'),
 ('grapes', 'mango'),
 ('apple', 'orange'),
 ('banana', 'mango'),
 ('banana', 'grapes')]

Test Case 2

uniqueCombinations(['apple', 'orange', 'apple'])
[('apple', 'orange'), ('apple', 'apple'), ('orange', 'apple')]

Is there a better / more elegant / more accurate way to do this??

I tried to get the all unique pair combinations from a list.

Here is what I have done so far,

import itertools

# Unique Combination Pairs for list of elements
def uniqueCombinations(list_elements):
    l = list(itertools.combinations(list_elements, 2))
    s = set(l)
    # print('actual', len(l), l)
    return list(s)
sample = ["apple", "orange", "banana", "grapes", "mango"]
uniqueCombinations(sample)

Output

[('apple', 'banana'),
 ('orange', 'mango'),
 ('orange', 'grapes'),
 ('apple', 'grapes'),
 ('orange', 'banana'),
 ('apple', 'mango'),
 ('grapes', 'mango'),
 ('apple', 'orange'),
 ('banana', 'mango'),
 ('banana', 'grapes')]

Is there a better / more elegant / more accurate way to do this??

I tried to get the all unique pair combinations from a list.

Here is what I have done so far,

import itertools

# Unique Combination Pairs for list of elements
def uniqueCombinations(list_elements):
    l = list(itertools.combinations(list_elements, 2))
    s = set(l)
    # print('actual', len(l), l)
    return list(s)

Test Case 1

sample = ["apple", "orange", "banana", "grapes", "mango"]
uniqueCombinations(sample)

Output

[('apple', 'banana'),
 ('orange', 'mango'),
 ('orange', 'grapes'),
 ('apple', 'grapes'),
 ('orange', 'banana'),
 ('apple', 'mango'),
 ('grapes', 'mango'),
 ('apple', 'orange'),
 ('banana', 'mango'),
 ('banana', 'grapes')]

Test Case 2

uniqueCombinations(['apple', 'orange', 'apple'])
[('apple', 'orange'), ('apple', 'apple'), ('orange', 'apple')]

Is there a better / more elegant / more accurate way to do this??

I tried to get the all unique pair combinations from a list.

Here is what I have done so far,

import itertools

# Unique Combination Pairs for list of elements
def uniqueCombinations(list_elements):
    l = list(itertools.combinations(list_elements, 2))
    s = set(l)
    # print('actual', len(l), l)
    return list(s)
sample = ["apple", "orange", "banana", "grapes", "mango"]
uniqueCombinations(sample)

Output

[('apple', 'banana'),
 ('orange', 'mango'),
 ('orange', 'grapes'),
 ('apple', 'grapes'),
 ('orange', 'banana'),
 ('apple', 'mango'),
 ('grapes', 'mango'),
 ('apple', 'orange'),
 ('banana', 'mango'),
 ('banana', 'grapes')]

Is there a better / more elegant / more accurate way to do this??

I tried to get the all unique pair combinations from a list.

Here is what I have done so far,

# Unique Combination Pairs for list of elements
def uniqueCombinations(list_elements):
    l = list(itertools.combinations(list_elements, 2))
    s = set(l)
    # print('actual', len(l), l)
    return list(s)
sample = ["apple", "orange", "banana", "grapes", "mango"]
uniqueCombinations(sample)

Output

[('apple', 'banana'),
 ('orange', 'mango'),
 ('orange', 'grapes'),
 ('apple', 'grapes'),
 ('orange', 'banana'),
 ('apple', 'mango'),
 ('grapes', 'mango'),
 ('apple', 'orange'),
 ('banana', 'mango'),
 ('banana', 'grapes')]

Is there a better / more elegant / more accurate way to do this??

I tried to get the all unique pair combinations from a list.

Here is what I have done so far,

import itertools

# Unique Combination Pairs for list of elements
def uniqueCombinations(list_elements):
    l = list(itertools.combinations(list_elements, 2))
    s = set(l)
    # print('actual', len(l), l)
    return list(s)
sample = ["apple", "orange", "banana", "grapes", "mango"]
uniqueCombinations(sample)

Output

[('apple', 'banana'),
 ('orange', 'mango'),
 ('orange', 'grapes'),
 ('apple', 'grapes'),
 ('orange', 'banana'),
 ('apple', 'mango'),
 ('grapes', 'mango'),
 ('apple', 'orange'),
 ('banana', 'mango'),
 ('banana', 'grapes')]

Is there a better / more elegant / more accurate way to do this??

Source Link
Pluviophile
  • 143
  • 1
  • 2
  • 9
Loading