Say I have a list, and I want to produce a list of all unique pairs of elements without considering the order. One way to do this is:
mylist = ['W','X','Y','Z']
for i in xrange(len(mylist)):
for j in xrange(i+1,len(mylist)):
print mylist[i],mylist[j]
W X
W Y
W Z
X Y
X Z
Y Z
I want to do this with iterators, I thought of the following, even though it doesn't have brevity:
import copy
it1 = iter(mylist)
for a in it1:
it2 = copy.copy(it1)
for b in it2:
print a,b
But this doesn't even work. What is a more pythonic and efficient way of doing this, with iterators or zip, etc.?