Find the intersection in python

355 viewsPython

Find the intersection in python

Have the function FindIntersection(strArr) read the array of strings stored in strArr which will contain 2 elements: the first element will represent a list of comma-separated numbers sorted in ascending order, the second element will represent a second list of comma-separated numbers (also sorted). Your goal is to return a comma-separated string containing the numbers that occur in elements of strArr in sorted order. If there is no intersection, return the string false.

Farjanul Answered question July 22, 2022
0

def FindIntersection(strArr):
  a = [ int(x) for x in strArr[0].replace(',','').split() if x.isdigit()]
  b = [ int(x) for x in strArr[1].replace(',','').split() if x.isdigit()]
  result = sorted(list(set(a).intersection(set(b))))
  temp = [str(x) for x in result]
  if len(temp) == 0:
    return False
  return ("," . join(temp))
 # keep this function call here 
print(FindIntersection(input()))

Farjanul Answered question July 22, 2022
0
You are viewing 1 out of 1 answers, click here to view all answers.