filmov
tv
Python Program To Check If Two Lists Have Common Elements|Python Programs For Begginers
Показать описание
The above video is about python program to check if two lists have common elements or not.If you have any doubts ,reach me out at the comments section.
This program can be written in two ways:
First way:
-create your own lists.
-initialise your result to false.
-traverse over the elements of the lists using for loop.
-check if any element of the first list is same as any element of second list.
-Then change your result to true.
-Finally print it
Second Way:
-convert your lists into sets.
-find the intersection of two sets and store it in another set.
-check if it has elements or not (check if the length of the newly created set has length '0' or not.)
This program can be written in two ways:
First way:
-create your own lists.
-initialise your result to false.
-traverse over the elements of the lists using for loop.
-check if any element of the first list is same as any element of second list.
-Then change your result to true.
-Finally print it
Second Way:
-convert your lists into sets.
-find the intersection of two sets and store it in another set.
-check if it has elements or not (check if the length of the newly created set has length '0' or not.)