Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Adding tuple to list without using built-in append method

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

[(i, j) for i in x for j in y if i != j]

Read about list comprehension

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading