Comparing the values of two lists in python

In this program, we will declare 3 lists in which one list will be empty list and other two will contain element now to iterate the first list element we will use for loop and then we will check if the same number is present in the remaining list or not if the number found in the second list but not found in 3rd list then we will add that number in 3rd list and print 3rd list


Implementation:

a = [10,20,30,40,20,50,60,70,80,90]
b = [10,30,45,60,73,80,85,90,95,100]
c = []
for number in a:
    if number in b:
        if number not in c:
            c.append(number)
print(c)
Output:
[10, 30, 60, 80, 90]

Happy Coding!

Follow us on Instagram @programmersdoor

Join us on Telegram @programmersdoor


Please write comments if you find any bug in the above code/algorithm, or find other ways to solve the same problem.

Follow Programmers Door for more.

#blog #interview #placement #learn #computer #science

19 views

        Contact Us

programmersdoor@gmail.com

  • LinkedIn
  • Facebook
  • Instagram

©2023 by Programmers Door