Looking for more info? Follow our learning guides and get started!

Find common values between 3 arrays.


import random #arrays x = [None] * 25 z = [None] * 25 y = [None] * 25 r1 = [None] * 25 r2 = [None] * 25 newlist = [] c = 0 #array counter for i in range (0,25): x[i] = random.randint(1,50) #randomizes numbers z[i] = random.randint(1,50) y[i] = random.randint(1,50) for i in range (0, 25): #finds common values between arrays x and z l = x[i] for u in range (0,25): if (z[u] == l): r1[c] = l c = c +1; r1 = [x for x in r1 if x != None] #removes None values from array c = 0 for i in range (0, 25): #finds common values between arrays r1 and y l = y[i] for u in range (0, len(r1)): if (r1[u] == l): r2[c] = l c = c +1; r2 = [x for x in r2 if x != None] #removes None values for i in r2: if i not in newlist: newlist.append(i) #removes duplicate values print ("1st array: ", x) print ("2nd array: ", z) print ("3rd array: ", y) print("-------------------------") print ("Common values", newlist)

Loading Please Wait...