Implement a program that, given two lists, outputs true if all the elements of the first list are in
the the second list, otherwise outputs false. Name your rule members(List1, List2), where List1 is the first list, List2 is the second list.
An example of a query using this rule would be:
members([a,d,h],[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]).
The expected output should be: true
An example of a query using this rule would be:
members([a,d,8],[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]).
The expected output should be: false
An example of a query using this rule would be:
members([],[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]).
The expected output should be: true

Respuesta :

Print sets 1 and 2 after converting the lists to sets. With set1 being the list1 and set2 being the list2, set1&set2 yields the common items set.

The above method is implemented in Python 3 as follows:

# Python program to find the common elements

# in two lists

def common_member(a, b):

   a_set = set(a)

   b_set = set(b)

   if (a_set & b_set):

       print(a_set & b_set)

   else:

       print("No common elements")

         

 

a = [1, 2, 3, 4, 5]

b = [5, 6, 7, 8, 9]

common_member(a, b)

 

a = [1, 2, 3, 4, 5]

b = [6, 7, 8, 9]

common_member(a, b)

Learn more about implemented here-

https://brainly.com/question/16130761

#SPJ4