You have two arrays in this kata, every array contain only unique elements. Your task is to calculate number of elements in first array which also are in second array.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Data structures

Starter code: def match_arrays(v, r):
	

Solutions:
def match_arrays(v, r):
	return sum((x in r for x in v))
verbose = False


def match_arrays(v, r):
	return sum((1 for x in v if x in r))
verbose = False


def match_arrays(v, r):
	cnt = 0
	for i in v:
		if i in r:
			cnt += 1
	return cnt
verbose = False


import collections
verbose = False

def setify(s):
	return {elt if isinstance(elt, collections.Hashable) else tuple(elt) for elt in s}

def match_arrays(v, r):
	return len(setify(v) & setify(r))


def match_arrays(v, r):
	tool = lambda x: {tuple(y) if type(y) == list else y for y in x}
	return len(tool(v) & tool(r))
verbose = False


(verbose, match_arrays) = (0, lambda a, b: sum((1 for e in a if e in b)))


def match_arrays(xs, ys):
	return sum((1 for y in ys if y in xs))
verbose = False


match_arrays = lambda k, l: len([e for e in k if e in l])
verbose = False