I have a list.
For example: [1, 2, 3, 4]
The result I would like to have is: [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]
.
So I would calculate all the possible couple (the order isn't important) with no equal elements. I did this:
result = []
for first_elem in my_list:
for second_elem in my_list:
if first_elem!=second_elem:
c = [first_elem,second_elem]
result.append(c)
return result
Is there a method to do this more efficient(here we have about n^2) without using libraries? Thanks
This didn't answer my question.