Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Ship Teams by oduvan
get_name = lambda a: a[0]
is_first_team = lambda a: a[1] > 40 or a[1] < 20
def two_teams(sailors):
team_1 = filter(is_first_team, sailors.items())
team_1 = sorted(map(get_name, team_1))
team_2 = filter(lambda a: a[0] not in team_1, sailors.items())
team_2 = sorted(map(get_name, team_2))
return [team_1, team_2]
if __name__ == '__main__':
print("Example:")
print(two_teams({'Smith': 34, 'Wesson': 22, 'Coleman': 45, 'Abrahams': 19}))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert two_teams({
'Smith': 34,
'Wesson': 22,
'Coleman': 45,
'Abrahams': 19}) == [
['Abrahams', 'Coleman'],
['Smith', 'Wesson']
]
assert two_teams({
'Fernandes': 18,
'Johnson': 22,
'Kale': 41,
'McCortney': 54}) == [
['Fernandes', 'Kale', 'McCortney'],
['Johnson']
]
print("Coding complete? Click 'Check' to earn cool rewards!")
Sept. 1, 2018
Comments: