It started as a discussion with a friend, who didn't fully grasp some way of setting defaults, but I thought the idea was cool enough for a beginner kata: binary `OR` each matching element of two given arrays (or lists, if you do it in Python; vectors in c++) of integers and give the resulting ORed array [starts to sound like a tonguetwister, doesn't it?].

If one array is shorter than the other, use the optional third parametero (defaulted to `0`) to `OR` the unmatched elements.

For example:

```python
or_arrays([1,2,3],[1,2,3]) == [1,2,3]
or_arrays([1,2,3],[4,5,6]) == [5,7,7]
or_arrays([1,2,3],[1,2]) == [1,2,3]
or_arrays([1,2],[1,2,3]) == [1,2,3]
or_arrays([1,2,3],[1,2,3],3) == [1,2,3]
```

Source: codewars | Difficulty: EASY
Tags: Bit manipulation

Data structures

Fundamentals

Starter code: def or_arrays(a, b, filler=0):
	

Solutions:
from itertools import zip_longest

def or_arrays(a1, a2, d=0):
	return [x | y for (x, y) in zip_longest(a1, a2, fillvalue=d)]


def or_arrays(a, b, d=0):
	return [(a[i] if i < len(a) else d) | (b[i] if i < len(b) else d) for i in range(max(len(a), len(b)))]


from itertools import zip_longest

def or_arrays(arr1, arr2, fill=0):
	return [a | b for (a, b) in zip_longest(arr1, arr2, fillvalue=fill)]


def or_arrays(arr1, arr2, n=0):
	result = []
	for i in range(max(len(arr1), len(arr2))):
		a = b = n
		if i < len(arr1):
			a = arr1[i]
		if i < len(arr2):
			b = arr2[i]
		result.append(b | a)
	return result


import itertools

def or_arrays(arr1, arr2, arg=0):
	return [i | j for (i, j) in itertools.zip_longest(arr1, arr2, fillvalue=arg)]


from itertools import zip_longest

def or_arrays(a, b, filler=0):
	return [x | y for (x, y) in zip_longest(a, b, fillvalue=filler)]


def or_arrays(arr1, arr2, o=0):
	xs = []
	i = 0
	while i < len(arr1) and i < len(arr2):
		xs.append(arr1[i] | arr2[i])
		i += 1
	while i < len(arr1):
		xs.append(arr1[i] | o)
		i += 1
	while i < len(arr2):
		xs.append(arr2[i] | o)
		i += 1
	return xs


def or_arrays(a, b, filler=0):
	(al, bl) = (len(a), len(b))
	return list([v[0] | v[1] for v in zip(a + [filler] * (max(al, bl) - al), b + [filler] * (max(al, bl) - bl))])


or_arrays = lambda a1, a2, d=0: [(a1[i] if i < len(a1) else d) | (a2[i] if i < len(a2) else d) for i in range(max(len(a1), len(a2)))]


def or_arrays(arr1, arr2, default=0):
	if len(arr1) < len(arr2):
		arr1 += [default] * (len(arr2) - len(arr1))
	if len(arr2) < len(arr1):
		arr2 += [default] * (len(arr1) - len(arr2))
	return [x | y for (x, y) in zip(arr1, arr2)]


def or_arrays(x, y, z=0, m=max, l=len):
	return [a | b for (a, b) in zip(x + [z] * (m(l(x), l(y)) - l(x)), y + [z] * (m(l(x), l(y)) - l(y)))]


def or_arrays(x, y, mod=0):
	m = maxLen = max(len(x), len(y))
	return [a | b for (a, b) in zip((x + [mod] * m)[:m], (y + [mod] * m)[:m])]


def ind(arr, i, default):
	return default if len(arr) - 1 < i else arr[i]

def or_arrays(arr1, arr2, default=0):
	return [ind(arr1, i, default) | ind(arr2, i, default) for i in range(max(len(arr1), len(arr2)))]


from itertools import zip_longest

def or_arrays(*args):
	(p, q, *c) = args
	return [a | b for (a, b) in zip_longest(p, q, fillvalue=c[0] if c else 0)]


from itertools import starmap, zip_longest
or_arrays = lambda a1, a2, f=0: list(starmap(int.__or__, zip_longest(a1, a2, fillvalue=f)))


def or_arrays(arr1, arr2, n=0):
	res = []
	i = 0
	while i < len(arr1) and i < len(arr2):
		res.append(arr1[i] | arr2[i])
		i += 1
	while i < len(arr1):
		res.append(arr1[i] | n)
		i += 1
	while i < len(arr2):
		res.append(arr2[i] | n)
		i += 1
	return res


def or_arrays(arr1, arr2, p=0):
	if len(arr2) > len(arr1):
		(arr2, arr1) = (arr1, arr2)
	arr2 += [p] * (len(arr1) - len(arr2))
	return [arr1[i] | arr2[i] for i in range(len(arr1))]


def or_arrays(arr1, arr2, d=0):
	(a, b) = sorted([arr1, arr2], key=len)
	a = a + (len(b) - len(a)) * [d]
	return [x | y for (x, y) in zip(a, b)]