Don Drumphet lives in a nice neighborhood, but one of his neighbors has started to let his house go.  Don Drumphet wants to build a wall between his house and his neighbor’s, and is trying to get the neighborhood association to pay for it.  He begins to solicit his neighbors to petition to get the association to build the wall.  Unfortunately for Don Drumphet, he cannot read very well, has a very limited attention span, and can only remember two letters from each of his neighbors’ names.  As he collects signatures, he insists that his neighbors keep truncating their names until two letters remain, and he can finally read them.

Your code will show Full name of the neighbor and the truncated version of the name as an array. If the number of the characters in name is less than or equal to two, it will return an array containing only the name as is"

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def who_is_paying(name):
	

Solutions:
who_is_paying = lambda n: [n, n[:2]] if len(n) > 2 else [n]


def who_is_paying(name):
	if len(name) > 2:
		return [name, name[0:2]]
	else:
		return [name[0:len(name)]]


def who_is_paying(name):
	return [name] * (len(name) > 2) + [name[:2]]


def who_is_paying(name):
	out = []
	if len(name) > 2:
		out.append(name)
		out.append(name[0:2])
	else:
		out.append(name)
	return out


def who_is_paying(name):
	var = []
	if len(name) <= 2:
		var.append(name)
		return var
	var.append(name)
	var.append(name[0] + name[1])
	return var


def who_is_paying(name):
	listsx = [name, ''.join(list(name)[:2])] if len(name) > 2 else [name]
	return listsx


def who_is_paying(name):
	return [name] if len(name) < 3 else [name, name[:2]]


from typing import List

def who_is_paying(name: str) -> List[str]:
	return [name, name[:2]] if len(name) > 2 else [name[:2]]


def who_is_paying(name):
	return sorted(set([name, name[:2]]), reverse=True)


def who_is_paying(name):
	return [name, name[:2]][not name[2:]:]


who_is_paying = lambda s: [s, s[:2]][:(len(s) > 2) + 1]


from collections import OrderedDict
who_is_paying = lambda n: list(OrderedDict.fromkeys([n, n[0:2]]))


def who_is_paying(donald_trump):
	if len(donald_trump) > 2:
		for mexican in range(len(donald_trump)):
			return [donald_trump, donald_trump[False] + donald_trump[True]]
	return [donald_trump]


who_is_paying = lambda n: [n, n[:2]][:(len(n) > 2) + 1]


who_is_paying = lambda n: [n, n[:2]][:2 - (len(n) < 3)]


def who_is_paying(name=''):
	return [name, name[:2]] if name != name[:2] else [name]


def who_is_paying(name):
	oplst = [name]
	if len(name) <= 2:
		return oplst
	else:
		oplst.append(name[:2])
		return oplst


def who_is_paying(name):
	a = []
	if len(name) <= 2:
		a.append(name)
	else:
		a.append(name)
		a.append(name[:2])
	return a


def who_is_paying(name):
	petition = []
	if len(name) <= 2:
		petition.append(name)
		return petition
	else:
		nam = name[:2]
		petition.append(name)
		petition.append(nam)
		return petition


def who_is_paying(name):
	name_list = []
	if len(name) <= 2:
		name_list.append(name[0:2])
	elif len(name) == 0:
		name_list.append('')
	elif len(name) > 2:
		name_list.append(name)
		name_list.append(name[0:2])
	return name_list


def who_is_paying(name):
	if len(name) > 2:
		names = [name]
		names.append(name[:2])
		return names
	else:
		names = [name]
		return names


def who_is_paying(name):
	if len(name) > 2:
		short = name[0:2]
		val = []
		val.append(name)
		val.append(short)
		return val
	elif len(name) <= 2:
		val = []
		val.append(name)
		return val
	else:
		return None


def who_is_paying(name):
	a = []
	i = 0
	for item in name:
		i += 1
	if i > 2:
		a.append(name)
		a.append(name[0] + name[1])
	else:
		a.append(name)
	return a


def who_is_paying(name):
	res = [name]
	if len(name) > 2:
		res.append(name[0] + name[1])
	return res


def who_is_paying(name):
	if len(name) <= 2:
		char_list = [name]
		return char_list
	else:
		name_list = [name, name[:2]]
		return name_list


def who_is_paying(name):
	return len(name) > 2 and [name, name[:2]] or [name]


def who_is_paying(name):
	sliced = name[0:2]
	if sliced == name:
		return [sliced]
	return [name, sliced]


def who_is_paying(name):
	res = []
	if len(name) <= 2:
		res.append(name)
	else:
		res.append(name)
		res.append(name[0:2])
	return res


def who_is_paying(name):
	liste_finale = []
	if len(name) > 2:
		lettres = name[0] + name[1]
		liste_finale.append(name)
		liste_finale.append(lettres)
		return liste_finale
	else:
		liste_finale.append(name)
		return liste_finale


def who_is_paying(name):
	d = [name]
	if len(name) < 3:
		return d
	else:
		d.append(name[0:2])
		return d


def who_is_paying(name):
	list = [name]
	if len(name) > 2:
		list.append(name[0:2])
		return list
	else:
		return list


def who_is_paying(name):
	if len(name) < 3:
		return [name]
	else:
		first_two = name[0:2]
		return [name, first_two]


def who_is_paying(name):
	b = []
	if len(name) <= 2:
		b.append(name)
		return b
	else:
		b.append(name)
		b.append(name[:2])
	return b


def who_is_paying(name):
	if len(name) > 2:
		return [f'{name}', f'{name[0]}{name[1]}']
	else:
		return [f'{name}']


def who_is_paying(name):
	if len(name) == 1:
		return [name]
	elif name == '':
		return ['']
	elif name == name[0:2]:
		return [name]
	else:
		return [name, name[0:2]]


def who_is_paying(name):
	new_list = []
	new_list.append(name)
	if len(name) > 2:
		new_list += [name[:2]]
	else:
		new_list
	return new_list


def who_is_paying(name):
	if len(name) == 0:
		return ['']
	if len(name) <= 2:
		return name.split()
	alist = []
	alist.extend([name, name[0:2]])
	print(alist)
	return alist


def who_is_paying(name):
	names = [name]
	if len(name) > 2:
		truncated_name = name[:2]
		names.append(truncated_name)
	return names


def who_is_paying(name):
	total = len(name)
	if total >= 3:
		first = name[0]
		second = name[1]
		first_two = first + second
		final = list([name, first_two])
		return final
	else:
		final = list([name])
		return final


def who_is_paying(name):
	x = []
	y = []
	if len(name) <= 2:
		x.append(name)
	else:
		x.append(name)
		y.append(name[0])
		y.append(name[1])
		z = ''.join(map(str, y))
		x.append(z)
	return x


def who_is_paying(name):
	if len(name) >= 3:
		return [name, name[0] + name[1]]
	if len(name) <= 2:
		return [name]
	else:
		return ['']


def who_is_paying(name):
	final_list = [name]
	if len(name) <= 2:
		return final_list
	if len(name) > 2:
		name_list = list(name)
		final_list.append(str(name_list[0] + name_list[1]))
		return final_list


def who_is_paying(name):
	r = [name]
	if len(name) > 2:
		r = [name, name[:2]]
	return r


def who_is_paying(name):
	m = []
	if len(name) <= 2:
		m.append(name)
		return m
	g = [name, name[:2]]
	return g


who_is_paying = lambda n: sorted({n, n[:2]})[::-1]


def who_is_paying(name):
	name_array = []
	if len(name) > 2:
		name_array.append(name)
		name_array.append(name[0:2])
		return name_array
	else:
		name_array.append(name)
		return name_array


def who_is_paying(name: str) -> list:
	return name[:2].split(' ') if len(name) <= 2 else name.split() + [name[:2]]


def who_is_paying(name):
	trunc = name[:2]
	arr = [name, trunc]
	if len(name) < 3:
		arr.pop()
	return arr


def who_is_paying(name):
	if len(name) == 1 or len(name) == 2:
		return [name]
	list = [name]
	if len(name) > 1:
		list.append(name[0] + name[1])
	elif len(name) > 0:
		list.append(name[0])
	return list


def who_is_paying(n):
	nn = n[:2] if len(n) > 2 else n
	return [n] if n == nn else [n, nn]


def who_is_paying(name):
	if len(name) > 2:
		trunc_name = name[0:2]
		output = [name, trunc_name]
	else:
		output = [name]
	return output


def who_is_paying(name):
	if name == '':
		return ['']
	elif name == 'I':
		return ['I']
	elif name == name[0:2]:
		return [name]
	else:
		return [name, name[0:2]]


def who_is_paying(name):
	if len(name) == 0:
		return ['']
	elif len(name) < 3:
		return [name]
	else:
		return [name, name[:2]]


def who_is_paying(name):
	if len(name) > 2:
		return list((name, name[:2]))
	else:
		return [name]


def who_is_paying(name):
	if len(name) > 2:
		list = []
		for char in name:
			list.append(char)
		a = ''
		a += list[0]
		a += list[1]
		list2 = []
		list2.append(name)
		list2.append(a)
		return list2
	else:
		list = []
		list.append(name)
		return list


def who_is_paying(name):
	if len(name) <= 2:
		return [name]
	else:
		name_list = list(name)
		name_2 = name_list[0:2]
		name_str = ''.join(name_2)
		return [name, name_str]


def who_is_paying(name):
	if len(name) > 2:
		tup1 = [name, name[:2]]
		return tup1
	else:
		tup2 = [name]
		return tup2


def who_is_paying(name):
	result = []
	if len(name) < 3:
		result.append(name)
		return result
	elif len(name) == 0:
		result.append('')
		return result
	result.append(name)
	result.append(name[:2])
	return result


def who_is_paying(name):
	names_list = []
	if len(name) <= 2:
		names_list.append(name)
		return names_list
	names_list.append(name)
	names_list.append(name[:2])
	return names_list


def who_is_paying(name):
	s = []
	if len(name) > 2:
		s.append(name)
		izi = name[:2]
		s.append(izi)
		return s
	if len(name) <= 2:
		s.append(name)
		return s
who_is_paying('')


def who_is_paying(name):
	namelist = []
	namelist.append(name)
	if len(name) <= 2:
		return namelist
	if len(name) > 2:
		namelist.append(name[:2])
		return namelist


def who_is_paying(name):
	ans = list()
	sec = ''
	if len(name) <= 2:
		ans = [name]
	else:
		sec = name[0:2]
		ans = [name, sec]
	return ans