How to compress this whole loop into one single line. Is there any way?
aa = []
for x in args:
for y in args:
if x == y:
pass
else:
kk = x*y
aa.append(kk)
How to compress this whole loop into one single line. Is there any way?
aa = []
for x in args:
for y in args:
if x == y:
pass
else:
kk = x*y
aa.append(kk)
from itertools import product
aa = [x*y for x,y in product(args, args) if x != y]
Absolutely nothing wrong with previous answer. A double loop also works and might be a little simpler to understand.
[x * y for x in args for y in args if x != y]