I want to add the tuple to a list without using built-in append method. My code is below:
def allPairs(x,y):
mylist = []
for i in x:
for j in y:
if i!=j:
mylist.append((i,j))
return mylist
Is there any alternate code for it to use in Python, that I can use in place of ‘append’ method?
>Solution :
[(i, j) for i in x for j in y if i != j]
Read about list comprehension