The following appears in my Python 2.6 code:
for src, dst in ([s,d] for s in universe for d in universe if s != d):
Can I do much better? What I particularly don't like is that I'm in effect specifying the same pair twice, once for the for loop and again for the generator expression. I'm uncertain whether I'd prefer:
for src, dst in itertools.product(universe, universe):
if src != dst:
Is there a way to express this loop concisely?
universe
happens to be a list, if it makes any difference. Order of iteration doesn't matter.