Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear and readable solution in Clear category for The Ship Teams by akamus
def two_teams(sailors):
ship_1 = []
ship_2 = []
for surname, age in sailors.items():
if age < 20 or age > 40:
ship_1.append(surname)
else:
ship_2.append(surname)
ship_1 = sorted(ship_1)
ship_2 = sorted(ship_2)
return [ship_1] + [ship_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!")
Oct. 7, 2024
Comments: