ye ye
ye ye

Reputation: 27

function which finds a common number in multiple lists

how would this function be completed to return the common integers between two lists?

how would i complete the get_common_elements(list1, list2) function?. The function should select all the common integers from both parameters and displays them in the result.

ie numbers 1 = 3,6,8,9,12,35
   numbers 2 = 6,7,13,34, 35
result = 6,35

you can assume that each number only occurs in each list once

Upvotes: 0

Views: 20

Answers (1)

Ramanjaneyalu T
Ramanjaneyalu T

Reputation: 36

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")  

Upvotes: 1

Related Questions