I don't believe this precise question has been asked before. I was recently faced with a problem where I had to find just such a set. An example would probably help:-
Given some list:
list1 = ['a', 'b']
Is there a function that returns the following set?
output = {('a', 'b'), ('a', 'a'), ('b', 'b'), ('b', 'a')}
I have been able to generate the desired output using the itertools combinations_with_replacement and permutations functions, as follows:
from itertools import combinations_with_replacement, permutations
set1 = set(combinations_with_replacement(['a', 'b'], 2))
set2 = set(permutations(['a', 'b'], 2))
>>> set1
{('a', 'b'), ('a', 'a'), ('b', 'b')}
>>> set2
{('b', 'a'), ('a', 'b')}
set1.update(set2)
>>> set1
{('a', 'b'), ('a', 'a'), ('b', 'b'), ('b', 'a')}
Is there a name for such a set? Is there an alternative method I can use?