Assume I have a set:
s = {1,2,3,4,5}
And now I want to perform an operation of every possible unordered pair of that set, say addition. For a list I would do:
for i in range(len(s)):
for j in range(i+1,len(s)):
print(s[i]+s[j]
But for a set the best I could come up with is:
for idx, val in enumerate(s):
for idx2, val2 in enumerate(s):
if idx2<=idx:
continue
print(val+val2)
Which does not seem satisfactory to me: One because the code has a higher complexity and also because it is less clear. What would be a pythonic (and fast) way to do this?