Today was a sad day. Having bought a new beard trimmer, I set it to the max setting and shaved away at my joyous beard. Stupidly, I hadnt checked just how long the max setting was, and now I look like Ive just started growing it!

Your task, given a beard represented as an arrayof arrays, is to trim the beard as follows:

['|', 'J', '|', '|'],
['|', '|', '|', 'J'],
['...', '...', '...', '...'];

To trim the beard use the following rules:

trim any curled hair --> replace 'J' with '|'
trim any hair from the chin (last array) --> replace '|' or 'J' with '...'

All sub arrays will be same length. Return the corrected array of arrays

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Data structures

Starter code: def trim(beard):
	

Solutions:
def trim(beard):
	return [[h.replace('J', '|') for h in b] for b in beard[:-1]] + [['...'] * len(beard[0])]


def trim(beard):
	beard = [['|' if p in '|J' else '...' for p in hair] for hair in beard]
	beard[-1] = ['...' for _ in beard[-1]]
	return beard


def trim(a):
	return [['|' if y == 'J' else y for y in x] for x in a[:-1]] + [['...'] * len(a[0])]


def trim(beard):
	for row in range(0, len(beard)):
		for hair in range(0, len(beard[row])):
			if row != len(beard) - 1:
				beard[row][hair] = '|'
			else:
				beard[row][hair] = '...'
	return beard


def trim(beard):
	for (i, a) in enumerate(beard):
		if i != len(beard) - 1:
			beard[i] = ['|' if v in 'J|' else v for v in a]
		else:
			beard[i] = ['...' for v in a]
	return beard


def trim(beard):
	return [list(map(lambda x: x.replace('J', '|'), arr)) for arr in beard[:-1]] + [['...'] * len(beard[0])]


def trim(beard):
	width = len(beard[0])
	beard = [['|' if cell in '|J' else '...' for cell in row] for row in beard[:-1]]
	beard.append(['...'] * width)
	return beard


def trim(beard):
	return [[c.replace('J', '|') for c in row] for row in beard[:-1]] + [['...'] * len(beard[-1])]


H = {'J': '|', '|': '|', '...': '...'}
trim = lambda b: [[H[h] for h in m] for m in b[:-1]] + [['...'] * len(b[-1])]


def trim(beard):
	return [['|' if j in ['|', 'J'] else j for j in i] for i in beard[:-1]] + [['...'] * len(beard[-1])]